Reputation: 107
how can I assign the Form closing event to the menustrip item click method ?
this.Closing += new CancelEventHandler(this.Form1_Closing);
private void Form1_Closing(object sender, CancelEventArgs e)
{
//
}
private void izlazToolStripMenuItem_Click(object sender, EventArgs e)
{
//
}
thanks
Upvotes: 0
Views: 346
Reputation: 495
Another way you could hook up the Close method to the Click event on your menu item is through the use of a lambda expression. The following code in the form's constructor demonstrates this:
public Form1()
{
InitializeComponent();
this.izlazToolStripMenuItem.Click += (s, a) => this.Close();
}
More information on lambda expressions can be found here: http://msdn.microsoft.com/en-us/library/vstudio/bb397687.aspx
Upvotes: 0
Reputation: 46008
You probably want to close the the Form in click event, so:
private void izlazToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
This will trigger Closing
event.
Upvotes: 3