【问题标题】:How to Save Form after User Exits?用户退出后如何保存表单?
【发布时间】:2020-06-24 16:06:59
【问题描述】:

当用户想要退出时,我想向它显示询问的消息框,

你想退出吗?

如果用户想留下并选择“否”,我如何保存表单?

【问题讨论】:

标签: c# windows forms events


【解决方案1】:

使用Form.FormClosing() 事件来检测表单的关闭并将数据保存在其中。

using System.Windows.Forms;

public class MyForm : Form
{
    this.FormClosing += new FormClosingEventHandler(this.FormIsClosing);
    
    private void MyForm_FormClosing(object sender, FormClosingEventArgs e)
    {
        if(DialogResult.No == MessageBox.Show("Do You Want to Exit?","Close My Application", MessageBoxButtons.YesNo, MessageBoxIcon.Information))
        {
            // Cancel the Closing event
            e.Cancel = true;
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-08
    • 1970-01-01
    • 2022-01-09
    • 2014-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多