Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Action when form is closed

Tags:

c#

How to make as by pressing to the close button, make so that the form was not closed, and it was turned off?

private void Form1_Closed(object sender, EventArgs e)
{
    Form1.Hide();
}

So the form is all the same closed.

like image 441
Saska Avatar asked Jul 12 '26 12:07

Saska


2 Answers

You should do it on FormClosing not FormClosed event like this:

private void Form1_FormClosing(object sender, EventArgs e) {
    Form1.Hide();
    e.Cancel = true;
}

FormClosed means the form is already closed.

like image 138
MadBoy Avatar answered Jul 15 '26 01:07

MadBoy


You want to interrupt the form closing event and cancel it, for example to minimize:

private void Form_FormClosing(object sender, FormClosingEventArgs e)
{
   e.Cancel = true;
   this.WindowState = FormWindowState.Minimized;
}
like image 28
Nick Craver Avatar answered Jul 15 '26 02:07

Nick Craver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!