ToolTip covered by ToolStripItems if they have dropdowns?

On Windows Forms β€” if there are tooltips and dropdown elements in the MenuStrip drop-down elements, the tooltip will have a 50% chance of being lower than ToolStripItems.

What is the workaround?

For playback, you can create a MenuStrip in Visual Studio or simply add the following code to the form and then try to hover over the menu items to get a hint:

        //Make a menu strip
        MenuStrip menu = new MenuStrip();            
        this.Controls.Add(menu);

        //Add category "File"
        ToolStripMenuItem fileItem = new ToolStripMenuItem("File");
        menu.Items.Add(fileItem);

        //Add items
        for (int i = 0; i < 10; i++)
        {
            ToolStripMenuItem item = new ToolStripMenuItem("item");
            item.ToolTipText = "item tooltip";
            item.DropDownItems.Add("sub item");

            fileItem.DropDownItems.Add(item);
        }

I am using .NET 3.5

+3
source share
2 answers

Try this code

//Make a menu strip
MenuStrip menu = new MenuStrip();
this.Controls.Add(menu);

//Add category "File"
ToolStripMenuItem fileItem = new ToolStripMenuItem("File");
menu.Items.Add(fileItem);

this.toolTip = new ToolTip();
this.toolTip.AutoPopDelay = 0;
this.toolTip.AutomaticDelay = 0;
this.toolTip.UseAnimation = true;

//Add items
for (int i = 0; i < 10; i++)
{
    ToolStripMenuItem item = new ToolStripMenuItem("item");

    //disable the default tool tip of ToolStripMenuItem
    item.AutoToolTip = false;

    //instead, use Tooltip class to show to text when mouse hovers the item
    item.MouseHover += new EventHandler(item_MouseHover);
    item.DropDownItems.Add("sub item");

    fileItem.DropDownItems.Add(item);
}

void item_MouseHover(object sender, EventArgs e)
{
    ToolStripMenuItem mItem = (ToolStripMenuItem)sender;
    toolTip.Show("tool tip", mItem.Owner, 1500);
}
+2
source

Source: https://habr.com/ru/post/1740110/


All Articles