MenuStrip Event Handler - Where?


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.
 
Ad

Advertisements

P

Pavel Minaev

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.
 
Ad

Advertisements

M

Mark Lawton

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!
 

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