Rubi Reubi
Rubi Reubi

Reputation: 103

How can i disable the tooltip from the TreeView control?

I didn't add any tooltips to the control. Not in designer not in the code. But on some items in the TreeView when i put the mouse on the item i see like a tooltip window message of the item name.

Can't figure out why there is a tooltip on some items.

The only event i have register on the TreeView control in the designer is AfterSelect.

private void tvFolders_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
    //Populate folders and files when a folder is selected
    this.Cursor = Cursors.WaitCursor;

    //get current selected drive or folder
    TreeNode nodeCurrent = e.Node;

    //clear all sub-folders
    nodeCurrent.Nodes.Clear();

    if (nodeCurrent.SelectedImageIndex == 0) 
    {
        //Selected My Computer - repopulate drive list
        PopulateDriveList();
    }
    else 
    {
        //populate sub-folders and folder files
        PopulateDirectory(nodeCurrent, nodeCurrent.Nodes);
    }
    this.Cursor = Cursors.Default;
}

In the designer

this.tvFolders.Dock = System.Windows.Forms.DockStyle.Left;
this.tvFolders.ImageIndex = 0;
this.tvFolders.ImageList = this.m_imageListTreeView;
this.tvFolders.Location = new System.Drawing.Point(0, 0);
this.tvFolders.Name = "tvFolders";
this.tvFolders.SelectedImageIndex = 0;
this.tvFolders.Size = new System.Drawing.Size(168, 357);
this.tvFolders.TabIndex = 2;
this.tvFolders.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tvFolders_AfterSelect);
// 
// m_imageListTreeView
// 
this.m_imageListTreeView.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("m_imageListTreeView.ImageStream")));
this.m_imageListTreeView.TransparentColor = System.Drawing.Color.Transparent;
this.m_imageListTreeView.Images.SetKeyName(0, "");
this.m_imageListTreeView.Images.SetKeyName(1, "");
this.m_imageListTreeView.Images.SetKeyName(2, "");
this.m_imageListTreeView.Images.SetKeyName(3, "");
this.m_imageListTreeView.Images.SetKeyName(4, "");
this.m_imageListTreeView.Images.SetKeyName(5, "");
this.m_imageListTreeView.Images.SetKeyName(6, "");
this.m_imageListTreeView.Images.SetKeyName(7, "");
this.m_imageListTreeView.Images.SetKeyName(8, "");

I do want to make that when i move the mouse over an item in the TreeView(tvFolders) it will show a tooltip message.

  1. Why it's showing on some items tooltips messages and i didn't add any ?

  2. How to make that when i move the mouse over an item in the TreeView it will show a tooltip message with the item name ?

Upvotes: 3

Views: 1988

Answers (2)

Will Chen
Will Chen

Reputation: 21

You can disbale a message in Control.WndProc(Message) Method in the derived TreeView class:

private const int WM_NOTIFY = 0x4e;
protected override void WndProc(ref Message m)
{
    switch (m.Msg)
    {
        case WM_NOTIFY:// diable tooltips
            return;
    }
    base.WndProc(ref m);
}

Upvotes: 0

ib11
ib11

Reputation: 2568

To disable the automatic tooltip, you need to add a new class file to your project with an override code as follows.

using System.Windows.Forms; 

public class MyTreeView : TreeView { 
  protected override CreateParams CreateParams { 
    get { 
      CreateParams parms = base.CreateParams; 
      parms.Style |= 0x80;  // Turn on TVS_NOTOOLTIPS 
      return parms; 
    } 
  } 
} 

Then you need to build it. After that you will have a new control, a "MyTreeView" control in the toolbox to use.

You need to simply change the declaration in your designer class to use the custom TreeView:

this.tvFolders = new MyTreeView();

To answer your questions:

  1. The treeview control by default automatically adds a tooltip for long names that do not fit within the boundaries of the control.
  2. To force the tooltip to show on each item, you can simply use the Node.ToolTipText property.

Source: this on MSDN

Upvotes: 3

Related Questions