Good afternoon,
I'd like to have the <Enter> key recognized after entering text into a textbox. I've set the "AcceptsReturn" to True but that doesn't seem to have the effect that I desire.
Can you please tell me how to have the textbox accept an <Enter> key after text is entered?
Thanks very much.
Regards,
John
"Enter" key on textbox
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: "Enter" key on textbox
If you want multiple lines of text, set the TextBox's Multiline property to True.
If you want <Enter> to trigger a script or button, then you use the control's KeyUp or KeyDown event and respond to the Enter key:
http://www.sapien.com/blog/2011/06/13/p ... x-control/
David
If you want <Enter> to trigger a script or button, then you use the control's KeyUp or KeyDown event and respond to the Enter key:
PowerShell Code
Double-click the code block to select all.$textbox1_KeyUp=[System.Windows.Forms.KeyEventHandler]{ #Event Argument: $_ = [System.Windows.Forms.KeyEventArgs] if($_.KeyCode -eq 'Enter') { &$button1_Click } }For more info on the TextBox control refer to the follow article:
http://www.sapien.com/blog/2011/06/13/p ... x-control/
David
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: "Enter" key on textbox
You have to trap and handle the "keypress" event:
PowerShell Code
Double-click the code block to select all.$textbox1_KeyPress=[System.Windows.Forms.KeyPressEventHandler]{ #Event Argument: $_ = [System.Windows.Forms.KeyPressEventArgs] if($_.KeyChar -eq 13){ [void][System.Windows.Forms.MessageBox]::Show('Enter key enterd'+$_.KeyChar) } }
Re: "Enter" key on textbox
Wow. That was tough to reverse-engineer. I'd never added/changed an event before so had to determine how to accomplish that first.
For anyone else in the same boat, create the textbox, then, from the designer screen, highlight the textbox, look for the textbox in the bottom left corner, highlight your textbox name, right-click and select "Add Events". From there the remainder of the suggestions should get you through.
Works great!!!
Thank you both very much.
Best regards,
John
For anyone else in the same boat, create the textbox, then, from the designer screen, highlight the textbox, look for the textbox in the bottom left corner, highlight your textbox name, right-click and select "Add Events". From there the remainder of the suggestions should get you through.
Works great!!!
Thank you both very much.
Best regards,
John