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

Stop new line in edit box

Status
Not open for further replies.

AlastairP

Technical User
Feb 8, 2011
286
AU
I am trying to prevent a new line being added to an edit box when the user presses the "enter" key or "shift + enter"
Is there a way to do this?
 
Yes.

Turn on the form's KeyPreview property, and in control's KeyPress check the key that was pressed. If it's what you want to disregard, issue NODEFAULT.

I gotta ask, though, why? Most people are really familiar with text editors and/or word processors and pretty much expect the enter key to bring a new line. Changing that expectation seems a mighty up-hill battle.
 
Hi Dan,
I also had no use for this until I built a form for creating a report with 6 x images per page and a caption for each image.
I just want the caption to be 2-300 Char long in a edit box with no scroll bars, where the max length property allows the control to be filled up just nicely.
By allowing the user to enter new lines, the text will drop off the bottom.
The caption text on the report form will be fixed - no stretching allowed.
Alastair
 
It worked a treat, Thanks

Code:
LPARAMETERS nKeyCode, nShiftAltCtrl
IF nKeyCode=13
	NODEFAULT
ENDIF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top