Answered TAB-Problems mixing NET-controls AND ABL-widgets

Hi everybody,

Found a simple demo-program here (Question - Using Ocx Microsoft richtextbox) that uses richtextbox together with some ABL-buttons in one frame. My problem is:
  • when the program starts, richtextbox has focus and one can't TAB-out of it.
  • as soon as you have pressed one of the buttons, you can useTAB to cycle through the other ABL-Buttons, but focus is never returned to the richtextbox.
I was playing around with NET-Properties "TabStop" and "TabIndex", but nothing helps.

Am I missing something ?

Cringer Moderator
Staff member
Mixing widgets like that is bound to find such problems unfortunately. I think what you'll need to do is to write your own handlers. So on the tab of the ABL widget before the .Net control, programmatically tab into the .Net control. On the tab of the .Net control, force entry to the next ABL widget.
Looked quite easy at first glance, but now i'm struggeling since hours.... I hope somebody can help me, because I'm absolutely stuck.

I have the following code:

/* If TAB is pressed on the FillIn before the textbox, move focus to the textbox */
ON TAB OF cFillIn-Before DO:

/* Then I defined a procedure which should be called everytime a key is released, when the textbox has Focus.
Have to use KeyUp, because TAB and SHIFT-TAB are not passed to KeyPressed, as I read in the Microsoft-documentation */

/* and I have another Procedure, which is called, when the textbox is left again */

Both procedures display only messages at the moment, like "KeyUp" and "TextBoxLeft", just to find out what happens. What I noticed is the following:
  • If I press TAB on the Fill-In, Focus goes to the textBox and I see the message "KeyUp".
  • If I press TAB again, I get only "TextBoxLeft", no "KeyUp", although I definitely pressed TAB again. Same with SHIFT-TAB.
  • All other keys I press (like F1, F2, BackSpace.....) work, I always get the message "KeyUp"
My conclusion: TAB and SHIFT-TAB call the KeyUp-Procedure only when focus was on an ABL-widget before, not when it is on the textbox.
One possible solution would be, to APPLY "ENTRY" TO cFillIn-after" in the TextBoxLeft-procedure, which works. But in this procedure I get only EventArgs, not KeyEventArgs, so I can't determine, if TAB or BACK-TAB was pressed.

That's the point where I'm stuck and have no clue at all how to go on. Hope somebody can help.

TIA, Wolf
Thanks Osborne, IT WORKS !!!

I saw this KB-Article before, but didn't pay much attention, because of a comment in the Microsoft-docs:
"You should not put any logic in the PreviewKeyDown event handler, other than to set the IsInputKey property".

I will go on with this solution and see, if there are any side-effects.