e.cancel = true如何在formclosing事件中起作用? [英] How does e.cancel=true works in formclosing event?

查看:77
本文介绍了e.cancel = true如何在formclosing事件中起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户故意关闭获胜表格时,我希望在数据库中进行一些更改。



我尝试了什么:



I want some changes to be made in the database when the user deliberately closes the win form.

What I have tried:

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
       {
           if(e.CloseReason==CloseReason.UserClosing)
           {
               e.Cancel = true; /* if it is true then it can be seen that the
                                 statements inside the formclosing methods runs
                                  twice(which causes the problem) before going to
                                  formclosed. when i set it to false then the problem
                                  gets resolved and y is that so */
               this.Hide();
               UpdateToken();
           }
       }

推荐答案

您需要知道的所有内容都写在这里:

表格.FormClosing事件(System.Windows.Forms)| Microsoft Docs [ ^ ]

CancelEventArgs.Cancel Property(System.ComponentModel)| Microsoft Docs [ ^ ]
All what you need to know has been written here:
Form.FormClosing Event (System.Windows.Forms) | Microsoft Docs[^]
CancelEventArgs.Cancel Property (System.ComponentModel) | Microsoft Docs[^]


这篇关于e.cancel = true如何在formclosing事件中起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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