只要没有单击任何项​​,就防止ToolStripDropDownButton被关闭

时间:2010-05-12 14:46:40

标签: c# .net

如果单击打开菜单的项目或箭头,我怎样才能阻止ToolStripDropDownButton关闭?

一个标准的.net Winforms ToolStripDropDownButton保持其菜单与你用鼠标悬停菜单时一样长...

我想在关闭事件中捕获它,然后说e.Cancel = false但不幸的是,似乎ToolStripDropDownButton没有关闭事件只是ToolStripDropDown

1 个答案:

答案 0 :(得分:4)

ToolStripDropDownButton只是ToolStripDropDown的包装器。你可以使用它的DropDown属性来访问ToolStripDropDown,如下所示:

ToolStripDropDownButton buttonStates = new ToolStripDropDownButton();
buttonStates.DropDown.Closing += new ToolStripDropDownClosingEventHandler(buttonStatesDropDown_Closing);

private void buttonStatesDropDown_Closing(object sender, ToolStripDropDownClosingEventArgs e)
{
    e.Cancel = true;
}