-
Nov 23rd, 2020, 07:32 AM
#1
Thread Starter
Junior Member
-
Nov 23rd, 2020, 08:12 AM
#2
Re: Assiging Enter key to multiple buttons
Please remember next time...elections matter!
-
Nov 23rd, 2020, 09:38 AM
#3
Re: Assiging Enter key to multiple buttons
you may try something like :
VB.net Code:
Private sub enter_keydown (ByVal sender as object, ByVal e as System.Windows.Form.KeyEventArgs) handles textbox1.Keydown, textbox2.keydown, .... dim name=ctype(sender,textbox).name If e.KeyCode = Keys.Enter Then Select case name case "Textbox1" button1_Click(sender,e) . . Case "Textbox4" button4_Click(sender,e) end select end if end sub
Last edited by Delaney; Nov 23rd, 2020 at 10:21 AM.
The best friend of any programmer is a search engine
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
-
Nov 24th, 2020, 02:19 PM
#4
Re: Assiging Enter key to multiple buttons
Originally Posted by Delaney
you may try something like :
Code:
Private sub enter_keydown (ByVal sender as object, ByVal e as System.Windows.Form.KeyEventArgs) handles textbox1.Keydown, textbox2.keydown, ....
dim name=ctype(sender,textbox).name
If e.KeyCode = Keys.Enter Then
Select case name
case "Textbox1"
button1_Click(sender,e)
.
.
Case "Textbox4"
button4_Click(sender,e)
end select
end if
end sub
Code:
button1.PerformClick
or
Code:
button4.PerformClick
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 24th, 2020, 02:28 PM
#5
Thread Starter
Junior Member
Re: Assiging Enter key to multiple buttons
TysonLPrice, Delaney and paul. Many thanks. Much appreciated.
Last edited by teos983; Nov 24th, 2020 at 03:13 PM.
-
Nov 24th, 2020, 02:33 PM
#6
Re: Assiging Enter key to multiple buttons
Originally Posted by teos983
Delaney and paul. Many thanks. Much appreciated.
I guess I should have posted code for you instead of a link on how to do it.
Please remember next time...elections matter!
-
Nov 24th, 2020, 03:39 PM
#7
Thread Starter
Junior Member
Re: Assiging Enter key to multiple buttons
Originally Posted by TysonLPrice
I guess I should have posted code for you instead of a link on how to do it.
No. This is not true. Your link was very helpful. You won't believe me I know. But I forgot to include your name when writing a "thank you" reply. I hope you forgive me for this mistake.
-
Nov 24th, 2020, 05:00 PM
#8
Re: [RESOLVED] Assiging Enter key to multiple buttons
Looking at Delaney's code, you could use something like this...
Code:
Public Class Form5
Dim pairs As New Dictionary(Of TextBox, Button)
Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
pairs.Add(TextBox1, Button6)
pairs.Add(TextBox2, Button7)
pairs.Add(TextBox3, Button8)
pairs.Add(TextBox4, Button9)
For Each kvp As KeyValuePair(Of TextBox, Button) In pairs
AddHandler kvp.Key.KeyDown, AddressOf enter_keydown
AddHandler kvp.Value.Click, AddressOf buttons_click
Next
End Sub
Private Sub enter_keydown(ByVal sender As Object, ByVal e As KeyEventArgs)
If e.KeyCode = Keys.Enter Then
pairs(DirectCast(sender, TextBox)).PerformClick()
End If
End Sub
Private Sub buttons_click(ByVal sender As Object, ByVal e As EventArgs)
MsgBox(DirectCast(sender, Button).Text)
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Tags for this Thread
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
|