单击关闭按钮时隐藏表单而不是关闭 [英] Hide form instead of closing when close button clicked

查看:25
本文介绍了单击关闭按钮时隐藏表单而不是关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户单击表单上的 X 按钮时,如何隐藏它而不是关闭它?

When a user clicks the X button on a form, how can I hide it instead of closing it?

我在 FormClosing 中尝试了 this.hide() 但它仍然关闭了表单.

I have tried this.hide() in FormClosing but it still closes the form.

推荐答案

像这样:

private void MyForm_FormClosing(object sender, FormClosingEventArgs e)
{
    if (e.CloseReason == CloseReason.UserClosing) 
    {
        e.Cancel = true;
        Hide();
    }
}

(来自 蒂姆·霍夫曼)

这篇关于单击关闭按钮时隐藏表单而不是关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆