本文介绍了DataGridView 上的工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我将鼠标悬停在 DataGridView 中的一行上时,我有一个工具提示显示 - 除了在显示它的行上时工具提示闪烁外,效果很好.
I've got a ToolTip showing when hovering over a row in my DataGridView - Works great except for the ToolTip flickering when over a row that displays it.
Private Sub DataGridView1_MouseHover(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseMove
Dim hit As DataGridView.HitTestInfo = DataGridView1.HitTest(e.X, e.Y)
If hit.Type = DataGridViewHitTestType.Cell Then
If Not hit Is m_HoveredItem Then
Me.ToolTip2.Hide(Me.DataGridView1)
m_HoveredItem = hit
If hit Is Nothing Then
Me.ToolTip2.SetToolTip(Me.DataGridView1, "")
Else
'Me.ToolTip2.SetToolTip(Me.DataGridView1, ConnectedUsers(Me.DataGridView1.Rows(hit.RowIndex).Cells("Database").Value, Instance))
Me.ToolTip2.Show(ConnectedUsers(Me.DataGridView1.Rows(hit.RowIndex).Cells("Database").Value, Instance), DataGridView1, e.X, e.Y)
End If
End If
End If
End Sub
我对 ListView 使用了类似的方法,效果很好:
I used a similar method for a ListView which worked great:
Private m_HoveredItem As ListViewItem
Private Sub lv_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dim lvi As ListViewItem = Me.LVDatabases.GetItemAt(e.X, e.Y)
If Not lvi Is m_HoveredItem Then
Me.ToolTip2.Hide(Me.LVDatabases)
m_HoveredItem = lvi
If lvi Is Nothing Then
Me.ToolTip2.SetToolTip(Me.LVDatabases, "")
Else
Me.ToolTip2.SetToolTip(Me.LVDatabases, ConnectedUsers(Me.LVDatabases.GetItemAt(e.X, e.Y).Text, Instance))
End If
End If
End Sub
推荐答案
Private cellColumnIndex As Integer = -1, cellRowIndex As Integer = -1
Private Sub testDataGridView_CellMouseMove(ByVal sender As Object, ByVal e As DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseMove
If e.ColumnIndex <> Me.cellColumnIndex OrElse e.RowIndex <> Me.cellRowIndex Then
Me.ToolTip2.Hide(Me.DataGridView1)
Me.cellColumnIndex = e.ColumnIndex
Me.cellRowIndex = e.RowIndex
If Me.cellColumnIndex >= 0 AndAlso Me.cellRowIndex >= 0 Then
Me.ToolTip2.SetToolTip(Me.DataGridView1, ConnectedUsers(Me.DataGridView1.Rows(e.RowIndex).Cells("Database").Value, Instance))
End If
End If
End Sub
这篇关于DataGridView 上的工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!