Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trap Cursor Movement in a Text Box on a Form.

Classes and Objects

Trap Cursor Movement in a Text Box on a Form.

by  EzLogic  Posted    (Edited  )
This worked for me in VFP,6, 7, 8

The problem:
When we use the text box in VFP on a form, it is a little clumsy. What I mean is when you hit the backspace and you are at the beginning of the text box, the cursor leaves the text box and jumps to the previous box (according to your tab order), especially when the user hits the backspace and holds it to delete the entire content (It happens with me too).

Also, I hated it when I pressed the down/up key and the cursor jumps to different objects on the form.

So, this is what I DID:
[color blue]
-Create a new class based on TEXTBOX and name it what you wish (mine is TeknoBox)
-Open the Class Designer and modify it.
-Go to the class property
-Add Property "[color red]cNotify[/color]"
-Add Property "[color red]OkToLeave[/color]"
[/color]
In the [color red]GotFocus() Event[/color] of the TextBox:
[color blue]this.cnotify = SYS(2001,'NOTIFY')
SET NOTIFY OFF
This.oktoleave = .T.[/color]

In the [color red]KeyPress() Event:[/color]
[color blue]
LPARAMETERS jKeyCode, jShiftAltCtrl
IF jKeyCode = 127 OR jKeyCode = 4 OR jKeyCode = 19 OR;
jKeyCode = 24 OR jKeyCode = 5 OR jKeyCode = 6 OR jKeyCode = 1
this.Oktoleave = .f.
ELSE
this.oktoleave = .t.
ENDIF [/color]

In the [color red]lostfocus() Event:[/color]
[color blue]
DO case
CASE this.cNotify = 'ON'
SET NOTIFY ON
CASE THIS.CNOTIFY = 'OFF'
SET NOTIFY OFF
ENDCASE[/color]

In the [color red]Valid() Event:[/color]
[color blue]
LOCAL lOkToleave
lOkToLeave = this.OkToLeave
this.OkToLeave = .t.
RETURN lOkToLeave[/color]


Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top