简体   繁体   English

Winforms Treeview节点工具提示自定义

[英]Winforms Treeview Node Tooltip Customization

For displaying tooltips in a treeview I set ToolTipText for each node and ShowNodeToolTip=True . 为了在树视图中显示工具提示 ,我为每个节点设置了ToolTipText ,并为ShowNodeToolTip=True设置了ShowNodeToolTip=True Ok that's easy. 好的,这很容易。 My question is now, how can I customize the tooltips appearance? 我现在的问题是,如何自定义工具提示外观? How can I change for example the time the ToolTip remains visible or the background color ? 如何更改工具提示保持可见时间背景颜色 Or should I use the tooltip control for that? 或者我应该使用工具提示控件吗?

TreeView has its own built-in ToolTip "control", you can't change the way it behaves. TreeView有自己内置的ToolTip“控件”,你不能改变它的行为方式。 If you want to customize it then just use your own ToolTip component. 如果要自定义它,只需使用自己的ToolTip组件即可。 The TreeView.NodeMouseHover event is a very good event to trigger it: TreeView.NodeMouseHover事件是一个非常好的事件来触发它:

    private void treeView1_NodeMouseHover(object sender, TreeNodeMouseHoverEventArgs e) {
        if (!string.IsNullOrEmpty(e.Node.ToolTipText)) {
            toolTip1.Show(e.Node.ToolTipText, treeView1);
        }
    }

Note that ToolTip.Show() has several overloads that lets you adjust position and duration of the tip. 请注意,ToolTip.Show()具有多个重载,可让您调整提示的位置和持续时间。 Changing the tip's background color requires setting the ToolTip.OwnerDraw property to True and implementing its Draw event. 更改提示的背景颜色需要将ToolTip.OwnerDraw属性设置为True并实现其Draw事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM