我正在尝试使用DataGridView_CellMouseEnter
事件来确定鼠标是否超过其中一个列标题,但我无法弄明白。
Private Sub DataGridView_CellMouseEnter(sender As Object, _
e As DataGridViewCellEventArgs) _
Handles DataGridView.CellMouseEnter
If (StrComp(e.ColumnIndex.ToString, "1")) Then
Me.Cursor = Cursors.WaitCursor
Else
Me.Cursor = Cursors.IBeam
End If
End Sub
如果有人可以帮助我,我会非常感激。
答案 0 :(得分:3)
RowIndex = -1应该告诉你:
Private Sub DataGridView1_CellMouseEnter(ByVal sender As Object, _
ByVal e As DataGridViewCellEventArgs) _
Handles DataGridView1.CellMouseEnter
If e.RowIndex = -1 And e.ColumnIndex > -1 Then
MessageBox.Show("Over " & DataGridView1.Columns(e.ColumnIndex).HeaderText)
End If
End Sub
答案 1 :(得分:1)
Private Sub dataGridView1_MouseEnter(ByVal sender as Object, ByVal e as EventArgs) Handles dataGridView1.MouseEnter
Dim relativeMousePosition as Point = dataGridView1.PointToClient(Cursor.Position)
Dim hit As DataGridView.HitTestInfo = dataGridView1.HitTest(relativeMousePosition.X, relativeMousePosition.Y)
Console.WriteLine(hit.Type.ToString())
End Sub