如何设置的ListView子项中的.Net工具提示 [英] How to set tooltips on ListView Subitems in .Net

查看:443
本文介绍了如何设置的ListView子项中的.Net工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置为我的ListView控件我的一些子项的工具提示文本。我无法得到刀尖露面。

任何人有什么建议吗?

 私人_timer定时器
私人小组定时器()
    如果_timer是Nothing然后
        _timer =新定时器
        _timer.Interval = 500
        AddHandler的_timer.Tick,AddressOf TimerTick
        _timer.Start()
    万一
结束小组
私人小组TimerTick(BYVAL发件人为对象,BYVAL E上的EventArgs)
    _timer.Enabled =假
结束小组受保护的覆盖子的OnMouseMove(BYVAL E上System.Windows.Forms.MouseEventArgs)
    如果不_timer.Enabled然后
        昏暗的项目= Me.HitTest(e.X,e.Y)
        如果没有产品没有AndAlso运算不item.SubItem是没有那么
            如果item.SubItem.Text =那
                昏暗的尖=新的工具提示
                昏暗P = item.SubItem.Bounds
                tip.ToolTipTitle =状态
                tip.ShowAlways = TRUE
                tip.Show(富,我,e.X,e.Y,1000)
                _timer.Enabled = TRUE
            万一
        万一
    万一    MyBase.OnMouseMove(五)
结束小组


解决方案

ObjectListView (约.NET的WinForms ListView的一个开放源代码包装)对细胞提示(是的,它用VB工作)内置支持。你听的 CellToolTip 事件,你可以做这样的事情(这是不可否认过多):

如果你不想使用ObjectListView,你需要继承的ListView,听 WM_NOTIFY 邮件,然后内的那些,以响应TTN_GETDISPINFO 的通知,在类似这样的方式:

 情况下TTN_GETDISPINFO:
    ListViewHitTestInfo信息= this.HitTest(this.PointToClient(Cursor.Position));
    如果(info.Item = NULL&放大器;!&安培;!info.SubItem = NULL){
        //调用一些自己的方法来获得你想要的工具提示
        字符串顶尖= this.GetCellToolTip(info.Item,info.SubItem);
        如果(!String.IsNullOrEmpty(尖)){
            NativeMethods.TOOLTIPTEXT TTT =(NativeMethods.TOOLTIPTEXT)m.GetLParam(typeof运算(NativeMethods.TOOLTIPTEXT));
            ttt.lpszText =提示;
            如果(this.RightToLeft == RightToLeft.Yes)
                ttt.uFlags | = 4;
            Marshal.StructureToPtr(TTT,m.LParam,FALSE);
            返回; //不做正常处理
        }
    }
    打破;

显然,这是C#,VB没有,但你的想法。

I am trying to set the tool tip text for some of my subitems in my listview control. I am unable to get the tool tip to show up.

Anyone have any suggestions?

Private _timer As Timer
Private Sub Timer()
    If _timer Is Nothing Then
        _timer = New Timer
        _timer.Interval = 500
        AddHandler _timer.Tick, AddressOf TimerTick
        _timer.Start()
    End If
End Sub
Private Sub TimerTick(ByVal sender As Object, ByVal e As EventArgs)
    _timer.Enabled = False
End Sub

Protected 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 (an open source wrapper around .NET WinForms ListView) has builtin support for cell tooltips (and, yes, it does work with VB). You listen for a CellToolTip event and you can do things like this (which is admittedly excessive):

If you don't want to use ObjectListView, you need to subclass ListView, listen for WM_NOTIFY messages, and then within those, respond to TTN_GETDISPINFO notifications, in a manner similar to this:

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;

Obviously, this is C#, not VB, but you get the idea.

这篇关于如何设置的ListView子项中的.Net工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆