我动态创建了81个按钮,我可以在任何这些按钮上检测到正常Click
,但我不确定如何检测右键单击。这是我的代码:
Private Sub btnArray_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim itemClicked As Button = CType(sender, Button)
Dim index As Integer = -1
For i As Integer = LBound(btnArray) To UBound(btnArray)
If btnArray(i) Is itemClicked Then
index = i
Exit For
End If
Next
If index > 0 Then
'MessageBox.Show("Sie haben den Button Nr. " & CStr(index) & " angeklickt")
End If
End Sub
答案 0 :(得分:0)
根据您要处理的时间(当用户单击按钮或用户释放点击时),您可以处理MouseDown
或MouseUp
事件。它们都有MouseEventArgs
类型的事件参数,告诉您单击了哪个鼠标按钮。
Private Sub btnArray_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs)
If e.Button = MouseButtons.Right Then
MessageBox.Show("You have right-clicked a button")
End If
End Sub