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

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
 
A

Adam Barker

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top