Preventing BackSpace key in a TextBox from moving a cursor to the previous control
Deleting characters in a TextBox with Backspace key doesn't stop when cursor reaches the beginning position but unexpectedly moves cursor to the previous control. It could cause unintended deletion of the data there.
To stop BackSpace key from leaving a TextBox and behave the same way as in other applications, add following code to a TextBox Keypress event. If you're using a Framework, add it to your lowest level TextBox class so it will be inherited by all TextBoxes.
This is sample code. Add error handling and adjust to your requirements as necessary. |
1 2 3 4 5 6 7 8 * TextBox Keypress LPARAMETERS nKeyCode, nShiftAltCtrl IF nKeyCode = 127 AND This.SelStart = 0 AND This.SelLength = 0 NODEFAULT ENDIF
Comments
Re: Preventing BackSpace key in a TextBox from moving a cursor t
it seems more apropiate there than in the KeyPress event
perfect
Solution
A question.
Working very very fine
You really did good. working very very fine.
Just change the "KeyPress_backSpace" with "KeyPress" only, and its really working.
thanks a lot.
Mr. Afaq Zahoor