Hello,
I am having a little trouble creating an event handler for a context menu
toolstripmenuitem.
I've seen various tutorials and so on, but I keep getting a bit stuck!
So far I have a second class defining the eventargs I want to use:
public class ApptEventArgs : EventArgs{
public int ApptUID;
public String ApptOp;
public int RowID;
public int ColID;
}
In my Forms class, I have declared an event:
public delegate void ApptEventHandler(object sender, ApptEventArgs e);
Then I have created a function to put the code in for when the event fires:
public void NewApptEvent(object sender, ApptEventArgs e)
{
MessageBox.Show("NEW Event Fired");
}
Finally, I am constructing the menu and trying the following to set the
arguments and configure my event to be used:
ApptEventArgs NewApptArgs = new ApptEventArgs();
NewApptArgs.ApptOp = "NEW";
NewApptArgs.ApptUID = 0;
NewApptArgs.ColID = ColIdx;
NewApptArgs.RowID = RowIdx;
//Create Menu Items
ToolStripMenuItem NewItem = new ToolStripMenuItem("New
Appointment",global::Itinerary.Properties.Resource s.NewAppt, new
ApptEventHandler(NewApptEvent(this,NewApptArgs)));
.......
When I compile, I get several errors, all on the last line where I am
configuring the new toolstrip item.
I get:
"Method Name expected"
"The best overloaded method for ...ToolStripMenuItem(string,
System.Drawing.Image, System.EventHandler) has some invalid arguments"
"Argument 3: Cannot convert from <project>.ApptEventHandler' to
'System.EventHandler'"
Any ideas?
I have tried various different ways of doing this but I always end up with
some or all of the above errors. I'm obviously not getting it!
At the end of the day, my Context Menu has about 5 main menus that pop out
submenus dynamically created depending on where you clicked, and I need to
fire off an event with those 4 parameters passed to it.
James.