P
PeterZ
Hoping one of you menu gurus can help out with this one....
I'm creating a sub menu programatically with X number of options.
The thing I'm stuck on is determining which menu option was pressed
within the menu event handler. Is there a way to pass the menu index
or menu text to the event handler?
-----------------------------------------
This is where I create the menu options:
-----------------------------------------
private void CreateSubMenu()
{
string sMenuText;
// Creates a sub menu with "Option 1", "Option 2", "Option 3",
etc...
for (int i=1; i <= giAvailableOps; i++)
{
sMenuText = "Option " + i.ToString();
MenuItem NewMenuItem = new MenuItem();
NewMenuItem.Text = sMenuText;
NewMenuItem.Click += new
System.EventHandler(this.mnuAddFeature_Click);
mnuAddFeature.MenuItems.Add(NewMenuItem);
}
}
---------------------------------------
My event handler for the menu options:
---------------------------------------
private void mnuAddFeature_Click(object sender, System.EventArgs e)
{
// I need to determine which menu option was pressed.
// The following code just returns "System.EventArgs"
MessageBox.Show(e.ToString());
}
I'm creating a sub menu programatically with X number of options.
The thing I'm stuck on is determining which menu option was pressed
within the menu event handler. Is there a way to pass the menu index
or menu text to the event handler?
-----------------------------------------
This is where I create the menu options:
-----------------------------------------
private void CreateSubMenu()
{
string sMenuText;
// Creates a sub menu with "Option 1", "Option 2", "Option 3",
etc...
for (int i=1; i <= giAvailableOps; i++)
{
sMenuText = "Option " + i.ToString();
MenuItem NewMenuItem = new MenuItem();
NewMenuItem.Text = sMenuText;
NewMenuItem.Click += new
System.EventHandler(this.mnuAddFeature_Click);
mnuAddFeature.MenuItems.Add(NewMenuItem);
}
}
---------------------------------------
My event handler for the menu options:
---------------------------------------
private void mnuAddFeature_Click(object sender, System.EventArgs e)
{
// I need to determine which menu option was pressed.
// The following code just returns "System.EventArgs"
MessageBox.Show(e.ToString());
}