I have a menu that I dynamically create like this:
ContextMenu MenuNote = new ContextMenu();
MenuNote.MenuItems.AddRange(new MenuItem[]
{
new MenuItem() { Name = "open", Text = "Ouvrir"},
new MenuItem() { Name = "mute", Text = "Sourdine"},
new MenuItem() { Name = "exit", Text = "Quitter" }
});
I don't create a reference because I wouldn't need these objects afterwards except for their respective events.
I then tried to do something like this, but I get an error that I cannot identify :
new MenuItem() { Name = "open", Text = "Ouvrir"}.Click += new EventHandler(MenuOpen_Click)
I get this error, and my research on "adding an event to an unreferenced object" didn't help me
Cannot implicitly convert type 'void' to 'System.Windows.Forms.MenuItem'
Do I really need to create references for each Items am I just wrong in the syntax ?
Thanks