簡體   English   中英

用戶退出后如何保存表單?

[英]How to Save Form after User Exits?

當用戶想要退出時,我想向它顯示消息框,詢問,

你想退出嗎?

如果用戶想留下並選擇“否”,我如何保存表單?

使用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;
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM