Make close button hide instead of closing [duplicate]
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?
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();
}
It should be pretty straight forward:
To cancel the closure of a form, set the
Cancel
property of theFormClosingEventArgs
passed to your event handler totrue
.
Concerning part two of the question with hiding the window, hide to taskbar or hide to notification area?
精彩评论