ListView工具提示闪烁

3
我有一个带有特定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个回答

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

那真是太棒了。谢谢。我之前在一个帖子中看到过这个建议,但没有使用show方法,而是一直在寻找设置位置的set方法。非常感谢。 - siddhesh jog
@siddheshjog 忘了提到我还改用了 Hide(...) 方法。 - LarsTech

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接