Saska
Saska

Reputation: 1021

Action when form is closed

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.

Upvotes: 7

Views: 46580

Answers (4)

Asad
Asad

Reputation: 21928

see Form.Closing Event

Here is the sample. you have several options

private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
  // this.Hide();
  // e.Cancel = true;
  this.Close();           

}

to remove a form both from the display, and from memory, it is necessary to Close rather than Hide it

Upvotes: 1

Nick Craver
Nick Craver

Reputation: 630449

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;
}

Upvotes: 1

Bobby
Bobby

Reputation: 11576

Use the FormClosing event, and set e.Cancel to true.

Upvotes: 0

MadBoy
MadBoy

Reputation: 11104

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.

Upvotes: 19

Related Questions