Stop backspace in VFP

by Craig Bailey on April 4, 2005

in General Tech

Here’s a tip Scott Scovell informed me of regarding a non-standard VFP behaviour:

‘I had a request from a client to prevent the textbox from losing the focus when they use BACKSPACE.

When removing details from a textbox using the BACKSPACE key, focus was being transferred to the previous textbox and they (more often then not) began to remove details from that textbox as well.

Windows standard

The standard behaviour appears to be that when using BACKSPACE, focus is not transferred to the previous control in the tab order. Try this creating a New email in Outlook and setting focus to the CC field. Using BACKSPACE observe that the control does not lose focus. FoxPro does lose focus and the previous control in the tab order get focus.

Solution

Surprising easy. In the Valid, test for LastKey() = BACKSPACE and This.Value is Empty() then return false (deny lose focus)

* Deny loss of focus when the backspace key is pressed and the control has an empty value
If Lastkey() = 127 And Empty(This.Value)
Return .F.
EndIf

* other checks etc…
Return .T.


{ 1 comment… read it below or add one }

Amit Goyal April 7, 2005 at 11:48 am

it works fine if the user is working with keyboard only but after deleting if users wants to go to another field by mouse then it is not possible.

Reply

Leave a Comment

blog comments powered by Disqus

Previous post:

Next post: