"How to create click event handler dynamically for each submenuitem"

  • Thread starter Thread starter Nikki
  • Start date Start date
N

Nikki

Hi,
I m developing a Windows application in which i want to create a
context menu, having variable number of submenus depending on the the
list in the file. I m able to create these submenus at runtime by
reading the file. But the problem is that there is no fixed count of
submenus and becaz of that i m not able to figure out "How to create
click event handler dynamically for each submenuitem"? Please help.
Thanks,
Nikki
 
Assign the same click event to each menu option, then in the handler use the
name to determine which was clicked.

ie.
public void AllMenuOptions_Clicked(object sender, ...)
{
switch( ((Control)sender).Name).ToString())
{
case "mnuFile":
<whatever>
break;

case "mnuEdit":
<whatever>
break;
}
}

You can do more funky stuff with reflection but thats a different story.
 
Back
Top