Thursday, July 3, 2008

How to Check Mouse Buttons State

Level: Beginner

Sometimes it is required to check the Mouse Button state on a certain point. For this purpose we use MouseButtons shared property,


Example: in DataGridView SelectionChanged event handler we can determine whether the selection is changed through mouse or not.

Private Sub DataGridView1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged
If System.Windows.Forms.Form.MouseButtons = Windows.Forms.MouseButtons.Left Then
' Selection is Changed by mouse
' Selection is NOT Changed by mouse
End If
End Sub

No comments: