在关闭窗体时发生。Closing 事件;
关闭窗体后发生。  Closed  事件;

解决方案 »

  1.   

    我的意思是比如我点了叉后,就会弹出一MessageBox问是否要保存文件,在C#里怎么做
      

  2.   

    this.Closing += new System.ComponentModel.CancelEventHandler(this.Form_Closing);private void Form_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
        if( !CreateMyForm( "请问是否要保存?" )
             //保存CODE
        else
             //不保存CODE 
    }bool CreateMyForm(string formTitle){
                bool result = false;
                System.Windows.Forms.Form form1 = new System.Windows.Forms.Form();
                form1.Text = formTitle;
             form1.MaximizeBox = false;
             form1.MinimizeBox = false;
                form1.AutoScale = false;
    form1.ClientSize = new System.Drawing.Size(190, 50);
                System.Windows.Forms.Button button1 = new System.Windows.Forms.Button();
                button1.Cursor = System.Windows.Forms.Cursors.Hand;
                System.Windows.Forms.Button button2 = new System.Windows.Forms.Button();
                button2.Cursor = System.Windows.Forms.Cursors.Hand;
            
                button1.Text = "保存";
                button1.Location = new System.Drawing.Point (10, 10);
                button2.Text = "不保存";
                button2.Location 
                    = new System.Drawing.Point( button1.Right+10,10 );
                button1.DialogResult = DialogResult.OK;            button2.DialogResult = DialogResult.Cancel;            form1.FormBorderStyle = FormBorderStyle.FixedDialog;
                form1.AcceptButton = button1;//
                form1.CancelButton = button2;
                form1.StartPosition = FormStartPosition.CenterScreen;
        
                form1.Controls.Add(button1);
                form1.Controls.Add(button2);
        
                form1.ShowDialog();
     
                if(form1.DialogResult == DialogResult.OK){
                    result = true;
                 this.Cursor = System.Windows.Forms.Cursors.AppStarting;
                }else{
                    result = false;
                 this.Cursor = System.Windows.Forms.Cursors.AppStarting;
                }
                form1.Dispose();
                return result;
    }
      

  3.   

    可以了,谢谢,可以说说
    this.Closing += new System.ComponentModel.CancelEventHandler(this.Form_Closing);
    的意思吗
      

  4.   

    委托:简单的说就是Closing操作映射到Form_Closing过程
      

  5.   

    就是FORM关闭时的事件和unload差不多
      

  6.   

    那如this.Closing += new System.ComponentModel.CancelEventHandler(this.Form_Closing);
    一般是放在什么地方。我对委托一窍不通。