M. X
M. X

Reputation: 1347

Winforms Treeview Node Tooltip Customization

For displaying tooltips in a treeview I set ToolTipText for each node and 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?

Upvotes: 3

Views: 4106

Answers (1)

Hans Passant
Hans Passant

Reputation: 942518

TreeView has its own built-in ToolTip "control", you can't change the way it behaves. If you want to customize it then just use your own ToolTip component. The TreeView.NodeMouseHover event is a very good event to trigger it:

    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. Changing the tip's background color requires setting the ToolTip.OwnerDraw property to True and implementing its Draw event.

Upvotes: 9

Related Questions