Can I programmatically expand a 'File' men

2019-07-11 05:03发布

Often when we click the File menu in the menu bar it expands downwards as seen in this

enter image description here

How can I achieve this programmatically via C# code? I need to expand the file menu as if the file menu is clicked.

标签: c# menu
1条回答
Anthone
2楼-- · 2019-07-11 05:31

Let's say the name of your MenuStrip is fileMenu, open it with:

fileMenu.ShowDropDown();

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();

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();
查看更多
登录 后发表回答