|
-
Dec 19th, 2007, 12:54 PM
#1
Thread Starter
Addicted Member
[RESOLVED] [2005] How do you type in a text box while a button is focused?
I'm making an app and when the user types in a textbox and presses enter-enter acts as the button that does something to the text.
Could somebody please help me?
Like on Google when you type in something and press enter and it returns a page of results.
Last edited by Louix; Dec 19th, 2007 at 01:04 PM.
-
Dec 19th, 2007, 01:12 PM
#2
Re: [2005] How do you type in a text box while a button is focused?
you can catch the enter key in the TextBox1_KeyUp event
vb Code:
Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
If e.KeyCode = Keys.Enter Then
Button1.PerformClick()
End If
End Sub
-
Dec 19th, 2007, 01:16 PM
#3
Re: [2005] How do you type in a text box while a button is focused?
It probably doesn't matter much, but generally I use the KeyPress event
vb.net Code:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Asc(e.KeyChar) = Keys.Enter Then
Button1.PerformClick()
End If
End Sub
-
Dec 19th, 2007, 01:19 PM
#4
Thread Starter
Addicted Member
Re: [2005] How do you type in a text box while a button is focused?
Thanks alot guys but is there anyway to stop it making the noise when you press enter?
Last edited by Louix; Dec 19th, 2007 at 01:27 PM.
-
Dec 19th, 2007, 01:31 PM
#5
Re: [2005] How do you type in a text box while a button is focused?
vb Code:
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then
e.SuppressKeyPress = True
Button1.PerformClick()
End If
End Sub
-
Dec 19th, 2007, 01:34 PM
#6
Thread Starter
Addicted Member
Re: [2005] How do you type in a text box while a button is focused?
-
Dec 19th, 2007, 02:09 PM
#7
Re: [RESOLVED] [2005] How do you type in a text box while a button is focused?
Another option that seems to have been overlooked here: You can set the AcceptButton property of the form. The button you choose will fire its Click event when you press Enter. (In VB6 and before, this is the equivalent of setting a button's "Default" property to True.)
"It's cold gin time again ..."
Check out my website here.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|