1

我正在尝试使用该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

如果有人可以帮助我,我将不胜感激。

4

2 回答 2

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
于 2012-07-19T18:05:02.430 回答
1

看看DataGridView.HitTest 方法

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
于 2012-11-19T14:56:15.047 回答