Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically Disable Particular Context Menu Item

Tags:

c#

.net

winforms

I've added 4 menus in context menu. If during the start context menu item is clicked, how to disable that particular ("Start") menu item?

ContextMenu conMenu1 = new ContextMenu();
public Form1()
{
            InitializeComponent();
    conMenu1.MenuItems.Add("Start", new System.EventHandler(this.Start_Click));
    conMenu1.MenuItems.Add("Pause", new System.EventHandler(this.Pause_Click));
    conMenu1.MenuItems.Add("Resume", new System.EventHandler(this.Resume_Click));
    conMenu1.MenuItems.Add("Stop", new System.EventHandler(this.Stop_Click));
}

private void Start_Click(object sender, EventArgs e)
{
    // Functionalities to disable start context menu item
}
like image 939
Vignesh Avatar asked Jun 28 '13 05:06

Vignesh


1 Answers

You can do like this. Handle the ContextMenu.Opening Event

private void conMenu1_Opening(object sender, CancelEventArgs e)
{
    conMenu1.Items[0].Enabled= false;
}
like image 131
Rajeev Kumar Avatar answered Nov 01 '22 00:11

Rajeev Kumar