开发者

Make close button hide instead of closing [duplicate]

开发者 https://www.devze.com 2022-12-30 15:59 出处:网络
This question already 开发者_JAVA百科has answers here: Hide form instead of closing when close button clicked
This question already 开发者_JAVA百科has answers here: Hide form instead of closing when close button clicked (7 answers) Closed 9 years ago.

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 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?

0

精彩评论

暂无评论...
验证码 换一张
取 消