在窗体关闭事件里写就可以了,加个timer不就得了

解决方案 »

  1.   

    在Closing里处理就行了,如加个退出的参数标志,看标志是否翻转了
      

  2.   

    可Closing不会停下来啊,继续下行执行,结果窗体就关闭了:(
    高手们能不能写两行代码啊?
    呵呵~~
      

  3.   

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;namespace WindowsApplication10
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Timer timer1;
    private System.ComponentModel.IContainer components;
    private int TimeControl=0;
    public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.components = new System.ComponentModel.Container();
    this.timer1 = new System.Windows.Forms.Timer(this.components);
    // 
    // timer1
    // 
    this.timer1.Interval = 1000;
    this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(292, 273);
    this.Name = "Form1";
    this.Text = "Form1";
    this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void Form1_Closing(object sender, CancelEventArgs e)
    {
    this.timer1.Start();
    if (this.TimeControl==0)
    {
    e.Cancel=true;
    }
    else
    {
    e.Cancel=false;
    }
    } private void timer1_Tick(object sender, System.EventArgs e)
    {
    this.TimeControl++;
    this.Dispose();
    }
    }
    }