ArM*_*MaN 3 c# winforms toolstripmenu
我在ac#winform项目上工作,主要的toolstripmenu在用户点击它的项目后不能隐藏,我该怎么做?

设置父菜单项的AutoClose属性以防止菜单条关闭.
展示:
ToolStripMenuItem file = new ToolStripMenuItem("File");
file.DropDown.AutoClose = false;
file.DropDownItems.Add("New");
file.DropDownItems.Add("Open");
file.DropDownItems.Add("Exit");
MenuStrip ms = new MenuStrip();
ms.Items.Add(file);
this.Controls.Add(ms);
Run Code Online (Sandbox Code Playgroud)
现在您有责任自己关闭菜单:
file.DropDown.Close();
Run Code Online (Sandbox Code Playgroud)
我在MSDN 论坛上找到了更好的答案。Dropdown 不会在点击时关闭,但在其他情况下会关闭:
DropDown.Closing += new ToolStripDropDownClosingEventHandler(DropDown_Closing);
...
private void DropDown_Closing(object sender, ToolStripDropDownClosingEventArgs e)
{
if (e.CloseReason == ToolStripDropDownCloseReason.ItemClicked)
{
e.Cancel = true;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2596 次 |
| 最近记录: |