我在vb.net 2010上。在我的winforms应用程序中,我有一个menuItem单击事件处理程序,可以通过鼠标单击或键盘快捷键调用。如何通过鼠标单击与键盘快捷键
调用我的处理程序Private Sub myToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles myMenuItemClick
Dim MouseClicked As Boolean
MouseClicked = ?? how to make the distinction how handler was called ??
If MouseClicked Then
lblClicked.Text = "Mouse Click"
Else
lblClicked.Text = "Key board shortcut"
End If
End Sub
答案 0 :(得分:1)
您可以处理ProcessCmdKey
表单并检查快捷方式,如果按下了快捷方式,则返回true。这样,点击仅通过点击而不是通过快捷方式提升:
Private Sub NewToolStripMenuItem_Click(sender As Object, e As EventArgs) _
Handles NewToolStripMenuItem.Click
MessageBox.Show("Click")
End Sub
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, keyData As Keys) _
As Boolean
If (Me.NewToolStripMenuItem.ShortcutKeys = keyData) Then
MessageBox.Show("ShortCut")
Return True
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function