开发者

Make close button hide instead of closing [duplicate]

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜