Create menu at run time?

  • Thread starter Thread starter Zanna
  • Start date Start date
Z

Zanna

Hi all!

Is it possible to add a MenuItem at run-time and handle the click event?

I can add the menu items, but no idea on managing the click...

Some tips?

Thanks
 
Hi all!

Is it possible to add a MenuItem at run-time and handle the click event?

I can add the menu items, but no idea on managing the click...

Some tips?

VB.NET:
See AddHandler and RemoveHandler

C#:
Wire-up the events using the += operator on the delegate. Sample:

button.Click += new EventHandler(this.CustomerClick);
....
public void CustomerClick(object sender, EventArgs e)
{
...
}
 
You have to use the overloaded method where you can specify the event
handler.

mnu.MenuItems.Add(itm, New EventHandler(AddressOf dynamicMenu_Click))

Protected Sub dynamicMenu_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs)

' sender.Index will contain the user selection

End Sub
 
Back
Top