简体   繁体   中英

How to Enable/Disable MenuStrip Items and Item's Drop Down Collection Items In C#

I want to know how can I disable/enable a MenuStrip Item and How to disable/enable a menustrip item's DropDownCollection particular item.

A Picture is given of my menustrip and "Account Department" is the DropDownCollection Item Which I want to Disable/Enable according to conditions.

I have a line of code which disable Main MenuStrip Item in this case "Departments" is the Item.

That line of code is:

menuStrip1.Items[1] = false;

Image Link

You can try this

menuStrip.Items[0].Visible = false; 

or

Use this Msdn site

You can see this link

如果您将该项目命名为“ Menu1”,则可以轻松启用或禁用它:

Menu1.Enabled = false;

As others said you can set the menu item's Enabled property, but It's better to give a name to the menu item that you are trying to change. then you can easily set it's enabled property as you want, for example name it menuitemAccountDepartment and then:

menuitemAccountDepartment.Enabled = false;

It's more readable and more manageable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM