如何确定网格鼠标指针中的哪个单元格结束?

时间:2012-11-19 07:02:00

标签: vb6 grid tooltip coordinates mousemove

Private Sub Grid1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    If  ????????????  Then Grid1.ToolTipText = <contents of cell>

End Sub

如何使用XY坐标来确定鼠标指针当前位于哪个单元格?

我使用的Grid的实施只有MouseMove个事件,而不是MouseOver个事件。

1 个答案:

答案 0 :(得分:1)

Private Sub Grid1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  Dim intRow As Integer, intCol As Integer
  With Grid1
    For intRow = 0 To .Rows - 1
      If y > .RowPos(intRow) Then
        If y < .RowPos(intRow) + .RowHeight(intRow) Then
          For intCol = 0 To .Cols - 1
            If x > .ColPos(intCol) Then
              If x < .ColPos(intCol) + .ColWidth(intCol) Then
                .ToolTipText = .TextMatrix(intRow, intCol)
              End If
            End If
          Next intCol
        End If
      End If
    Next intRow
  End With 'Grid1
End Sub