Hi,
The trick is to work the .NET way and use a custom enumeration. This makes your code much more readable.
For instance, Before the declaration for your first form (you can also create all enumerators ina seperate file), declare a new enumerator:
[tt]
public enum MenuSelected
{
None,
ItemOne,
ItemTwo,
ItemThree
}
[/tt]
The next step is to make sure that all your delegates point to the same event handler. This can be done in the designer by selecting the same method for each menuItem.Click event. However, the code is the following:
[tt]
menuItem2.Click += new System.EventHandler(OnMenuSelect);
menuItem3.Click += new System.EventHandler(OnMenuSelect);
menuItem4.Click += new System.EventHandler(OnMenuSelect);
[/tt]
The event method itself must:
1. Instantiate Form2.
2. Make sure that the "sender" is a menu item
3. Find out which object actually initiated the event
4. Run a PrepareForm method on Form2 which will do any pre-processing before...
5. Showing the form.
Here is the code:
[tt]
private void OnMenuSelect(object sender, System.EventArgs e)
{
// Instantiate Form2
Form2 frm2 = new Form2();
if (sender is MenuItem)
{
// Cast sender to MenuItem in order to access the specific methods
MenuItem mi = (MenuItem)sender;
MenuSelected selectedItem = MenuSelected.None;
// Find out which menuitem initiated the event.
switch (mi.Text)
{
case "Menu Item 1":
selectedItem = MenuSelected.ItemOne;
break;
case "Menu Item 2":
selectedItem = MenuSelected.ItemTwo;
break;
case "Menu Item 3":
selectedItem = MenuSelected.ItemThree;
break;
}
// execute method passing our enumerator
frm2.PrepareForm(selectedItem);
frm2.Show();
}
}
[/tt]
In Form2, all you need to implement is the PrepareForm method:
[tt]
public void PrepareForm(MenuSelected selectedItem)
{
if (selectedItem == MenuSelected.ItemOne)
MessageBox.Show("Item One Selected"

;
if (selectedItem == MenuSelected.ItemTwo)
MessageBox.Show("Item Two Selected"

;
if (selectedItem == MenuSelected.ItemThree)
MessageBox.Show("Item Three Selected"

;
}
[/tt]
That's it. Hope it helps.
Cheers!