Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load ' Handles MyBase.Load Me.KeyPreview = True '注册窗体的键盘事件 End Sub Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown If e.KeyCode = Keys.F2 Then Dosomething() End If End Sub Private Sub Dosomething() '你要的代码写这里。 TextBox7.Text = Keys.F2 End Sub
给button设置快捷键
If e.KeyCode = Keys.F1 Then Call btnAdd_Click(sender, e) ‘ID为btnAdd的单击事件 ElseIf e.KeyCode = Keys.F2 Then ’同上解释 Call btnNew_Click(sender, e) ElseIf e.KeyCode = Keys.F3 Then Call btnDelete_Click(sender, e) ElseIf e.KeyCode = Keys.F4 Then Call btnSearch_Click(sender, e) ElseIf e.KeyCode = Keys.F5 Then Call btnDo_Click(sender, e) ElseIf e.KeyCode = Keys.F6 Then Me.Close() End If