我可以以编程方式展开“文件"菜单吗? [英] Can I programmatically expand a 'File' menu?
问题描述
通常,当我们单击菜单栏中的文件菜单时,它会向下扩展,如此
Often when we click the File menu in the menu bar it expands downwards as seen in this
如何通过C#代码以编程方式实现这一目标?我需要展开文件菜单,就像单击文件菜单一样.
How can I achieve this programmatically via C# code? I need to expand the file menu as if the file menu is clicked.
推荐答案
假设您的MenuStrip名称为fileMenu
,请使用以下命令将其打开:
Let's say the name of your MenuStrip is fileMenu
, open it with:
fileMenu.ShowDropDown();
要显示SubMenuItem,请打开ParentMenuItem,然后打开SubMenuStrip.参考您的屏幕截图,我将把SubMenuItem命名为"newMenuStrip".
To show a SubMenuItem, open the ParentMenuItem and then the SubMenuStrip. Referring to your screenshot, I will name the SubMenuItem as "newMenuStrip".
fileMenu.ShowDropDown();
newMenuStrip.ShowDropDown();
尝试此操作时,MenuStrips中将看不到任何选择.因此,这是您的最终代码:
When you try this, you will see no selection in the MenuStrips. So, this is your final code:
fileMenu.ShowDropDown();
newMenuStrip.ShowDropDown();
newMenuStrip.DropDownItems[0].Selected();
这篇关于我可以以编程方式展开“文件"菜单吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!