【问题标题】:ListView ToolTip flickersListView 工具提示闪烁
【发布时间】:2012-09-13 20:54:32
【问题描述】:

我有一个具有特定 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

【问题讨论】:

    标签: vb.net winforms listview tooltip flicker


    【解决方案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 方法来设置位置。非常感谢。
    • @siddheshjog 忘了说我也改成使用Hide(...) 方法了。
    猜你喜欢
    • 2011-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    • 2016-09-06
    相关资源
    最近更新 更多