Reply to comment

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.

* TextBox Keypress
LPARAMETERS nKeyCode, nShiftAltCtrl
IF nKeyCode = 127 AND This.SelStart = 0 AND This.SelLength = 0
	NODEFAULT
ENDIF

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <java>, <powershell>, <tsql>, <visualfoxpro>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.