ListView ToolTip闪烁

时间:2012-09-21 12:16:03

标签: vb.net winforms listview tooltip flicker

我有一个带有某些id值的ListView。我使用movemove方法在工具提示中显示有关此ID的其他详细信息。

代码是用VB2003编写的,直到现在它都运行良好。最近我们迁移到了VB2008。

现在工具提示闪烁。详情如下。

希望这对.NET大男孩来说很容易。我是一名Java EE开发人员,所以我很少(不)知道我做错了什么。

编译器设置: 目标框架.NET 2.0

代码:

Dim m_HoveredItem As ListViewItem

Private Sub cancellationList_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles CancellationList.MouseMove
    Dim lvi As ListViewItem = Me.CancellationList.GetItemAt(e.X, e.Y)

    If Not lvi Is m_HoveredItem Then
        m_HoveredItem = lvi
        If lvi Is Nothing Then
            Me.cancelrejectToolTip.SetToolTip(Me.CancellationList, "")
        Else
            Dim orderText As String() = lvi.Text.Split("(")
            Dim orderRef As Integer = CInt(orderText(0).Trim)
            Dim orderIsin As String
            Dim orderDesc As String
            Dim order As AppOrder= New AppOrder(_server, orderRef)
            orderIsin = order.Isin
            orderDesc = order.OrderDescription
            cancelrejectToolTip.SetToolTip(Me.CancellationList, (orderRef.ToString & "/" & orderIsin & "/" & orderDesc))
        End If
    End If
End Sub

1 个答案:

答案 0 :(得分:1)

看起来鼠标移动一直在可见工具提示上移动,使其隐藏,但随后鼠标移动使其再次可见,并且循环继续。最简单的方法是使用Show方法偏移工具提示的位置:

Private Sub cancellationList_MouseMove(ByVal sender As Object, _
                                       ByVal e As MouseEventArgs) _
                                       Handles CancellationList.MouseMove
  Dim lvi As ListViewItem = Me.CancellationList.GetItemAt(e.X, e.Y)

  If Not lvi Is m_HoveredItem Then
    m_HoveredItem = lvi
    If lvi Is Nothing Then
      Me.cancelrejectToolTip.Hide(Me.CancelleationList) 
    Else
      Dim orderText As String() = lvi.Text.Split("(")
      Dim orderRef As Integer = CInt(orderText(0).Trim)
      Dim orderIsin As String
      Dim orderDesc As String
      Dim order As AppOrder= New AppOrder(_server, orderRef)
      orderIsin = order.Isin
      orderDesc = order.OrderDescription

      cancelrejectToolTip.Show(orderRef.ToString & "/" & orderIsin & "/" & orderDesc, _
                               Me.Cancellationlist, _
                               New Point(e.X + 16, e.Y + 16))
    End If
  End If
End Sub