开发者

"Tool tip" covered by ToolStripItems if they have dropdown items?

In Windows Forms - if the dropdown items of a MenuStrip has tooltips and dropdown items themselves the tooltip will have about a 50% chance of showing up below the ToolStripItems.

What is the workaround?

To repro you can create the MenuStrip in Visual Studio or just add the following code to a form and then try to hover your mouse over the menu items to get a tooltip:

        //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 it开发者_Python百科ems
        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


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);
}


There is an article on CodeProject that implements a derived version of ToolStrip with custom tool tip support. Could be an alternative solution. http://www.codeproject.com/Tips/376643/ToolStrip-with-custom-ToolTip

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜