单击关闭按钮时如何编写代码以关闭窗口 [英] how to write code for closing windows when close button is clicked

查看:78
本文介绍了单击关闭按钮时如何编写代码以关闭窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 对于窗口关闭按钮,关闭表单之前要求退出的代码是什么?如果用户接受,请关闭表单,否则关闭窗口.

感谢

解决方案

你好

在FormClosing事件中

 私有 无效 MyForm_FormClosing(对象发​​送者,FormClosingEventArgs e)
{
    如果(MessageBox.Show(" " ,
              MessageBoxButtons.YesNo,
                   MessageBoxIcon.Question)!= System.Windows.Forms.DialogResult.Yes)
        e.Cancel =  true ;
} 


[垃圾内容已删除,违者帐户已被禁用— SA]


hi for window close button, what is the code to ask for exit before closing the form?if user accepts,close the form,if not, stay in window.

thanks

解决方案

Hello

In FormClosing event

private void MyForm_FormClosing(object sender, FormClosingEventArgs e)
{
    if (MessageBox.Show("Are you sure to close the form?",
          "Question", 
              MessageBoxButtons.YesNo, 
                   MessageBoxIcon.Question) != System.Windows.Forms.DialogResult.Yes)
        e.Cancel = true;
}


[Spam content removed, offender''s account disabled — SA]


这篇关于单击关闭按钮时如何编写代码以关闭窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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