我想在DataGridView中有一个“帮助”光标,但只有第1行到行尾,不包括列标题。我目前使用的代码在datagridview控件上显示帮助光标 - 在列标题上甚至在行下的空白区域,因为我已将datagridview停靠在面板中。这可能很简单,但我该如何解决这个问题呢?我有代码在离开DataGridView时将光标设置回默认值。
Private Sub DataGridView1_CellMouseMove(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseMove
Dim dgv As DataGridView = DataGridView1
For r As Integer = 1 To dgv.RowCount - 1
Me.Cursor = Cursors.Help
Next
End Sub
Private Sub DataGridView1_CellMouseLeave(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellMouseLeave
Me.Cursor = Cursors.Default
End Sub
答案 0 :(得分:2)
这会将光标更改为仅在单元格上方时才有帮助。它排除了标题行和左列以及背景。您可以根据自己的需要更改条件
Private Sub DataGridView1_MouseMove(sender As Object, e As MouseEventArgs) Handles DataGridView1.MouseMove
Dim myHitTest = DataGridView1.HitTest(e.X, e.Y)
If myHitTest.RowIndex >= 0 AndAlso myHitTest.ColumnIndex >= 0 Then
DataGridView1.Cursor = Cursors.Help
Else
DataGridView1.Cursor = Cursors.Default
End If
End Sub