Hi,
I'm using Visual Basic 2005. I'm trying to create shortcut keys for my buttons. Currently, i have 2 buttons, presentButton and plotButton. When i press spacebar, it will perform the presentButton Click Event and when i press Enter, it will perform the plotButton Click Event. Is that possible?


Private Sub presentButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles presentButton.Click

If count >= threshold Then
Me.responsePictureBox.Visible = True
tmrTimer.Enabled = True
End If

End Sub

Private Sub plotButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles plotButton.Click

Audiogram.Show()
End Sub

Comments

Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

If e.KeyCode = 115 Then 'For F4 key

Call Button1_Click(Button1, e)

End If

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

MessageBox.Show(

yeah good job bumping a 3!!! years old thread....

:D
I guess it is better to try and solve those threads, than to leave them unsolved and have them return empty from a search engine. Plus, replying to posts seems to help out with educating one self in vb.net.

Well, minus well...:icon_smile:

Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.Space Then
            Button1.PerformClick()
        End If
        If e.KeyCode = Keys.Enter Then
            Button2.PerformClick()
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.KeyPreview = True '// set KeyPreview to True and not have other controls take Focus from the keys pressed.
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox("Button1_Clicked", MsgBoxStyle.Information)
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        MsgBox("Button2_Clicked", MsgBoxStyle.Question)
    End Sub
This article has been dead for over six months. Start a new discussion instead.