MenuCommand.Enabled Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets a value indicating whether this menu item is available.

Namespace:   System.ComponentModel.Design
Assembly:  System (in System.dll)

public virtual bool Enabled { get; set; }

Property Value

Type: System.Boolean

true if the item is enabled; otherwise, false.

The following code example creates a MenuCommand object, configures its properties, and adds it to IMenuCommandService.

[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] 
public class CDesigner : System.ComponentModel.Design.ComponentDesigner 
{
    public override void Initialize(IComponent comp) 
    {
        base.Initialize(comp);

        IMenuCommandService mcs = (IMenuCommandService)comp.Site.
                    GetService(typeof(IMenuCommandService));
        MenuCommand mc = new MenuCommand(new EventHandler(OnF1Help), StandardCommands.F1Help);
        mc.Enabled = true;
        mc.Visible = true;
        mc.Supported = true;
        mcs.AddCommand(mc);
        System.Windows.Forms.MessageBox.Show("Initialize() has been invoked.");
    }

    private void OnF1Help(object sender, EventArgs e) 
    {
        System.Windows.Forms.MessageBox.Show("F1Help has been invoked.");
    }
}

.NET Framework
Available since 1.1
Return to top
Show: