当用户单击Windows应用程序中的“关闭"(X)按钮时,如何显示警报消息框 [英] How to Display Alert Message Box When User Click ON Closed(X) Button In Windows Application

查看:62
本文介绍了当用户单击Windows应用程序中的“关闭"(X)按钮时,如何显示警报消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建Windows应用程序,其中有一种形式,即员工详细信息.如果用户以表格形式输入数据并单击关闭(X)"按钮,则消息框将显示您是否要保存数据".如果用户未输入详细信息,然后单击关闭(X)"按钮,则消息框将显示是"确定要退出".

I am creating windows application in which i have one form i.e. employee details. If user enter data in form and click on Closed(X) button than message box display "You want to saved data or not ".and if user does not enter details and clicked on Closed(X) button than message box display"Are you sure want to exit".

推荐答案



参见以下代码作为示例:
Hi,

see this code as an example:
public partial class Form1 : Form
{
   public Form1()
   {
      InitializeComponent();
      this.FormClosing +=new FormClosingEventHandler(Form1_FormClosing);
   }

   private void Form1_FormClosing(object sender, FormClosingEventArgs e)
   {
      if (e.CloseReason != CloseReason.UserClosing)
         return;

      if (String.IsNullOrEmpty(textBox1.Text))
      {
         if (MessageBox.Show("Are you sure you want to close the form?", "Warning", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
            e.Cancel = true;
      }
      else
      {
         if (MessageBox.Show("You want to save data or not?", "Warning", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
         {
            //Save data
         }
      }
   }
}


如何在用户单击"X"按钮时保存整个应用程序... ???
数据库应该更新... !!! 犯病" ????
How to save the whole application when user clicks the "X"button...???
Database should be updated...!!! "Commit" ill Work???


这篇关于当用户单击Windows应用程序中的“关闭"(X)按钮时,如何显示警报消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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