I have an FormClosing
event which is invoked by pressing the closing X of the window and also when I execute the this.Close()
command.
The issue is that I want to detect which of the 2 forms this event was invoked.
Event code.
private void MDIPrincipal_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("¿Desea salir del programa?", "Salir del Programa",
MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
Environment.Exit(1);
}
else e.Cancel = true;
}
I use this code to ask me Do you want to exit the program ?, before closing the form. But I do not want you to ask me when using this.Close()
Does anyone have any idea how to do it?
More Details .
In case it can not be detected from where it was invoked, an alternative solution occurred to me. Use an extra string detonador
parameter.
For example.
private void MDIPrincipal_FormClosing(object sender, FormClosingEventArgs e, string detonador = "")
{
if (detonador != "")
{
//Código aquí...
}
}
But I do not know how to implement it. Or also deactivating this event so that it is not invoked.
Example.
Event.MDIPrincipal_FormClosing.Disable();
This.Close();
The point is that I want the form to be closed without you asking me when using this.Close()
.