Is it possible? I need to call the Form1_FormClosing here:
ContextMenu trayMenu = new ContextMenu();
trayMenu.MenuItems.Add("Close", delegate {
Form1_FormClosing(????)
});
I need it because I’m using the CancelEventArgs from _FormClosing event:
private void Form1_FormClosing(object sender, CancelEventArgs e)
{
if (th != null && th.ThreadState == System.Threading.ThreadState.Running)
{
if (MessageBox.Show("the process is running, you want stop it?", "app", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
AbortProccess(); }
else
{
e.Cancel = true;
}
}
}
I hope this is clear,thanks in advance.
There are a few things you could do.
First, you could just close the form using
myForm.Close()as this will indirectly call theFormClosingevent. Also, you could move everything within theFormClosingevent into a separate method instead of in the event itself. You can then call that method from the event and from your MenuItem. If you don’t want to do either of those, you could try using this as the delegate: