MenuStrip Event Handler - Where?

  • Thread starter Thread starter Mark Lawton
  • Start date Start date
M

Mark Lawton

Using C# in Visual Studio 2008. I have added a menustrip with some
menu options to a form - but I cannot find the event handlers for them
anywhere. I have found the tool's setup code, which adds the created
menu items to the tool, and which is followed by:

private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem
newTimeRecordToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
reportToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
byProjectToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
byDeveloperToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
maintainToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
developersToolStripMenuItem;

Here is the form code:

namespace sandpit
{
public partial class Outer : Form
{
public Outer()
{
InitializeComponent();
}

private void Outer_Load(object sender, EventArgs e)
{

}
}
}

Where do I add code to handle the event of of an option being
selected, please?

It ought to be simple - but after an hour of searching books and the
WWW, I am still none the wiser.
 
Using C# in Visual Studio 2008. I have added a menustrip with some
menu options to a form - but I cannot find the event handlers for them
anywhere

Event handlers are not created for your controls automatically - you
need to do that yourself. You do it for menu items in precisely the
same way you do it for buttons - typically, it's: select the item in
the form so it's highlighted, switch to event list on the Properties
window, and double-click on the event you want to create the handler
for. Of course you can do it in the code, too, by registering the
handler with the appropriate event manually.

The event you're looking for is, unsusprisingly, named Click -
ToolStripMenuItem class inherits it from ToolStripItem.
 
Event handlers are not created for your controls automatically - you
need to do that yourself. You do it for menu items in precisely the
same way you do it for buttons - typically, it's: select the item in
the form so it's highlighted, switch to event list on the Properties
window, and double-click on the event you want to create the handler
for. Of course you can do it in the code, too, by registering the
handler with the appropriate event manually.

The event you're looking for is, unsusprisingly, named Click -
ToolStripMenuItem class inherits it from ToolStripItem.

Pavel,

Thank you very much for this simple but remarkably useful piece of
information!
 
Back
Top