5

How can I make the close button on a form effectively act as a 'Hide' button?

Is there a way to abort the FormClosing event?

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
adamwtiko
  • 2,865
  • 8
  • 39
  • 47

2 Answers2

14

You could just capture the FormClosing event and stop the default action, then instead of closing the form just hide it:

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    e.Cancel = true;
    this.Hide();
}
Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
djdd87
  • 67,346
  • 27
  • 156
  • 195
4

It should be pretty straight forward:

To cancel the closure of a form, set the Cancel property of the FormClosingEventArgs passed to your event handler to true.

Concerning part two of the question with hiding the window, hide to taskbar or hide to notification area?

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
cyberzed
  • 2,026
  • 1
  • 16
  • 26