vb.net – 如何在.Net中的ListView子项上设置工具提示

vb.net – 如何在.Net中的ListView子项上设置工具提示,第1张

概述我正在尝试为listview控件中的一些子项设置工具提示文本.我无法获得显示的工具提示. 有人有什么建议吗? Private _timer As TimerPrivate Sub Timer() If _timer Is Nothing Then _timer = New Timer _timer.Interval = 500 AddHan 我正在尝试为ListvIEw控件中的一些子项设置工具提示文本.我无法获得显示的工具提示.

有人有什么建议吗?

Private _timer As TimerPrivate Sub Timer()    If _timer Is nothing Then        _timer = New Timer        _timer.Interval = 500        AddHandler _timer.Tick,AddressOf TimerTick        _timer.Start()    End IfEnd SubPrivate Sub TimerTick(ByVal sender As Object,ByVal e As EventArgs)    _timer.Enabled = FalseEnd SubProtected OverrIDes Sub OnMouseMove(ByVal e As System.windows.Forms.MouseEventArgs)    If Not _timer.Enabled Then        Dim item = Me.HitTest(e.X,e.Y)        If Not item Is nothing AndAlso Not item.SubItem Is nothing Then            If item.SubItem.Text = "" Then                Dim tip = New tooltip                Dim p = item.SubItem.Bounds                tip.tooltipTitle = "Status"                tip.ShowAlways = True                tip.Show("FOO",Me,e.X,e.Y,1000)                _timer.Enabled = True            End If        End If    End If    MyBase.OnMouseMove(e)End Sub
解决方法 ObjectListView(围绕.NET WinForms ListVIEw的开源包装器)内置了对单元工具提示的支持(是的,它确实适用于VB).你监听一个Celltooltip事件,你可以做这样的事情(这无疑是过分的):

alt text http://i31.tinypic.com/20udbgo.png

如果您不想使用ObjectListVIEw,则需要继承ListVIEw,侦听WM_NOTIFY消息,然后在这些消息中,以类似于此的方式响应TTN_GETdisPINFO通知:

case TTN_GETdisPINFO:    ListVIEwHitTestInfo info = this.HitTest(this.PointToClIEnt(Cursor.position));    if (info.Item != null && info.SubItem != null) {        // Call some method of your own to get the tooltip you want        String tip = this.GetCelltooltip(info.Item,info.SubItem);         if (!String.IsNullOrEmpty(tip)) {            NativeMethods.tooltipTEXT ttt = (NativeMethods.tooltipTEXT)m.GetLParam(typeof(NativeMethods.tooltipTEXT));            ttt.lpszText = tip;            if (this.RightToleft == RightToleft.Yes)                ttt.uFlags |= 4;            Marshal.StructuretoPtr(ttt,m.LParam,false);            return; // do not do normal processing        }    }    break;

显然,这是C#,而不是VB,但你明白了.

总结

以上是内存溢出为你收集整理的vb.net – 如何在.Net中的ListView子项上设置工具提示全部内容,希望文章能够帮你解决vb.net – 如何在.Net中的ListView子项上设置工具提示所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1212769.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存