Can I programmatically expand a 'File' men

2019-07-11 04:58发布

问题:

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

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

回答1:

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


标签: c# menu