I have a text box in a form and I'm trying to capture when the return is hit an execute a go button on the form I have not been successful in getting it capture the enter instead it just executes the go button every time a key is pressed here is the code that I have(I think I'm on the right track but could be way off):
$textboxpath_KeyPress=[System.Windows.Forms.KeyPressEventHandler]{
if ($_.KeyChar -eq [System.Windows.Forms.Keys]::Enter)
{
$_.Handled = $true
}
}
Getting Enter key to execute a button from a textbox
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
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 LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Getting Enter key to execute a button from a textbox
Well i got it kind of figured out
$textboxpath_KeyPress=[System.Windows.Forms.KeyPressEventHandler]{
if ($_.KeyChar -eq [System.Windows.Forms.Keys]::Enter)
{
&$buttonGo_Click
}
}
Found out that if this $textboxpath.AutoCompleteMode = 'Suggest' is set then the enter will not take the enter. Any workaround?
$textboxpath_KeyPress=[System.Windows.Forms.KeyPressEventHandler]{
if ($_.KeyChar -eq [System.Windows.Forms.Keys]::Enter)
{
&$buttonGo_Click
}
}
Found out that if this $textboxpath.AutoCompleteMode = 'Suggest' is set then the enter will not take the enter. Any workaround?
Getting Enter key to execute a button from a textbox
You can set the button as the Form's AcceptButton and it will trigger the specified button whenever the user presses 'Enter'. The only side effect is that the form will also close.
Another alternative is to use the Form's KeyPreviewDown event. You will need to set the Form's KeyPreview property to True. I recommend searching the web for C# examples on how to do this.
David
Another alternative is to use the Form's KeyPreviewDown event. You will need to set the Form's KeyPreview property to True. I recommend searching the web for C# examples on how to do this.
David
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Getting Enter key to execute a button from a textbox
Thanks Davidc I got it working here is the code I used in case anyone else runs in to the problem
$textboxpath_Keydownpreview=[System.Windows.Forms.PreviewKeyDownEventHandler]{
if ($_.KeyCode -eq [System.Windows.Forms.Keys]::Enter)
{
&$buttonGo_Click
}
}
$textboxpath_Keydownpreview=[System.Windows.Forms.PreviewKeyDownEventHandler]{
if ($_.KeyCode -eq [System.Windows.Forms.Keys]::Enter)
{
&$buttonGo_Click
}
}
Getting Enter key to execute a button from a textbox
Well that will capture the enter key but now it is capturing ctrl+v and not pasting in the box.
Getting Enter key to execute a button from a textbox
I believe I have an easier way. Remove the other events and replace it with the KeyDown event:
$textbox1_KeyDown=[System.Windows.Forms.KeyEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.KeyEventArgs]
#TODO: Place custom script here
if($_.KeyCode -eq 'Enter')
{
&$buttonGo_Click
}
}
It triggers even if you have AutoComplete enabled. You can also use KeyUp event as an alternative.
David
$textbox1_KeyDown=[System.Windows.Forms.KeyEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.KeyEventArgs]
#TODO: Place custom script here
if($_.KeyCode -eq 'Enter')
{
&$buttonGo_Click
}
}
It triggers even if you have AutoComplete enabled. You can also use KeyUp event as an alternative.
David
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Getting Enter key to execute a button from a textbox
Your code still does not allow for pasting into the text box
Getting Enter key to execute a button from a textbox
I got it working with
$textboxpath_KeyUp=[System.Windows.Forms.KeyEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.KeyEventArgs]
if(($_.Control -eq $true) -and ($_.KeyCode -eq 'V'))
{
$textboxpath.Paste()
}
}
$textboxpath_KeyUp=[System.Windows.Forms.KeyEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.KeyEventArgs]
if(($_.Control -eq $true) -and ($_.KeyCode -eq 'V'))
{
$textboxpath.Paste()
}
}
Getting Enter key to execute a button from a textbox
Not sure why the copy paste doesn't work for you. I can't reproduce it on my end.
David
David
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Getting Enter key to execute a button from a textbox
I figured it out some how ShortcutsEnabled was set to false changed it to true and it is working now thanks for all your help!!!