如何关闭设置为autoclose = false的toolstripmenuitem? [英] How do I close a toolstripmenuitem that is set to autoclose = false?

查看:221
本文介绍了如何关闭设置为autoclose = false的toolstripmenuitem?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个菜单项,用户可以切换.我希望菜单保持打开状态,以便用户可以检查他们想要的所有项目.我设置autoclose = false,现在效果很好.但是,我现在也无法关闭窗口.我尝试在菜单上单击菜单,单击转义,单击菜单项,单击菜单的组合键,但无济于事.

I have a menu of items that the user can toggle. I wanted the menu to stay open so the user can check all the items they want. I set autoclose = false and now that works great. However, I also cannot close the window now lol. I tried clicking off of the menu onto the form, hitting escape, hitting the menu item, hitting the keycombo for the menu, nothing works.

理想情况下,我希望用户能够仅单击表单或除菜单以外的任何内容以将其关闭或按Escape键.我该怎么做?我尝试在表单上创建一个getfocus事件并执行item.HideDropDown,但没有骰子.

Ideally, I'd like the user to be able to just click the form or basically anything but the menu to close it or press escape. How would I accomplish that? I tried creating a gotfocus event on the form and doing item.HideDropDown in there but no dice.

谢谢!

推荐答案

为表单生成click事件,然后遍历,对于没有自己的click事件的每个控件,请将其click事件设置为一个表格.

Generate the click event for the form, and then go through and for every control that doesn't have its own click event, set its click event to the one for the form.

在事件中,包含隐藏菜单的代码:toolStripDropDownButton.HideDropDown();

In the event, include the code to hide the menu: toolStripDropDownButton.HideDropDown();

将代码复制到其他控件的任何现有单击事件中.

Copy the code to any existing click events for other controls.

这是当您单击表单上任何地方时我如何隐藏月历的方法.

This is how I handled hiding a monthcalendar when you click anywhere on the form.

如果您还希望包含按转义的选项,请对KeyDown事件执行相同的操作,并在运行代码之前检查其是否为转义键.

And if you want to also include pressing escape as an option, do the same thing with a KeyDown event, checking if it's the escape key before running the code.

这篇关于如何关闭设置为autoclose = false的toolstripmenuitem?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆