Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Handing The Escape Key
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00367335
Message ID:
00367464
Vues:
13
The default behavior for a textbox is to undo any changes made to the value in that textbox when the key is pressed. I believe the trick is to set the KeyPreview property to .T. for the form and use the NODEFAULT command in the KeyPress event of the form. Take a look at the sample code below.
DEFINE CLASS ctestescform AS form
	Top = 0
	Left = 0
	Height = 75
	Width = 375
	DoCreate = .T.
	Caption = "Escape Key Sample"
	KeyPreview = .T.
	Name = "frmEscKeyTest"

	ADD OBJECT txttest1 AS textbox WITH ;
		Value = "Some Text", ;
		Height = 23, ;
		Left = 24, ;
		Top = 12, ;
		Width = 100, ;
		Name = "txtTest1"

	ADD OBJECT txttest2 AS textbox WITH ;
		Value = "Some Text", ;
		Height = 23, ;
		Left = 24, ;
		Top = 36, ;
		Width = 100, ;
		Name = "txtTest2"

	PROCEDURE KeyPress(nKeyCode, nShiftAltCtrl)
		IF nKeyCode = 27 AND nShiftAltCtrl = 0
			NODEFAULT	&& This disables default behavior

			WITH this
				.WriteBuffer()

				IF .QueryUnload()
					.Release()
				ENDIF
			ENDWITH
		ELSE
			RETURN DODEFAULT(nKeyCode, nShiftAltCtrl)
		ENDIF
	ENDPROC

	PROCEDURE WriteBuffer()
		*-- Put code to force control's value to it's controlsource here
	ENDPROC

	PROCEDURE QueryUnload()
		*-- Put code to determine if changes made here
	ENDPROC
ENDDEFINE
>I tried that. It seems that the default escape behavior is taking place before my code. When Escape is pressed, the first thing that happens is the text dissappears, then my KeyPress event code fires.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform