开发者

Disable MenuStrip Dropdown in Windows Forms Application

I am disabling the parent menu option in a Windows forms menustrip. When you h开发者_如何学Cover over it, the submenu still opens. Is there a way to disable the submenu opening or do I have to disable all the submenu items?


Having the menu drop down show on mouse hover does not seem to be the default behavior of a ToolStripMenuItem and I could not find a property to enable this.

I did find this post by someone who wanted this behavior, and you should check to see if there is a MouseHover event handler for the ToolStripMenuItem and check the Enabled property there:

private void toolStripMenuItem1_MouseHover(object sender, EventArgs e)
{
    if (toolStripMenuItem1.Enabled)
        toolStripMenuItem1.DropDown.Show(menuStrip1, new Point(0, 0));
}

HTH


Just set the Enableproperty on the parent menu to False. In .net 2.0 and 3.5 the submenu will not show.

Also please try to be a little more specific.


I ended up looping through the DropDownItems and disabling them after I disable the main item.

for (int i = 0; i < this._menuOpen.DropDownItems.Count; i++)
{
    this.menuOpen.DropDownItems[i].Enabled = false;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜