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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stop the use of Enter Key

Status
Not open for further replies.

mstrcmtr

Programmer
Nov 14, 2007
103
PK
How can stop the use of Enter Key in edit box for going on next line
 
push key
ON KEY LABEL ENTER keyboard ""
*pop key ... when finished
 
Coding In KeyPress of Edit1 box

LPARAMETERS nKeyCode, nShiftAltCtrl

IF nKeyCode = 13 && Enter
PUSH KEY

ON KEY LABEL ENTER KeyBoard ""

=MESSAGEBOX('Enter Key not allowed in Message Box',0+16,'Use spacebar for next Line')

POP KEY

RETURN
ENDIF

Still enter key active not deactivate
 
Extend your EditBox class
Code:
DEFINE CLASS ExtendEditBox AS EditBox

	AllowEnters = .T.
	
	PROCEDURE KeyPress
	LPARAMETERS KeyCode, ShiftAltCtrl
	
		IF m.KeyCode = 13 AND !This.AllowEnters
			NODEFAULT
		ENDIF

	ENDPROC

ENDDEFINE
and set .AllowEnters in the same way that you set .AllowTabs.
 
As you can see, there are several different approaches.

The simplest is to add this code to the edit box's Keypress event:

Code:
PARAMETERS nKeyCode, nShiftAltCtrl

IF nKeyCode = 13
  NODEFAULT
ENDIF

Also, make sure that the form's KeyPreview property is set to .F. (which is the default).

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top