是这样的,我的程序里面有两个窗体:
form1、form2.
当关闭form1的时候我希望form1在关闭过程中等待4秒钟,让form2显示一些消息出来,让用户看到。
请问用timer该怎么做?
好像thread.sleep(4000)不行,它只把form2定住了,没有让form2把消息显示出来。

解决方案 »

  1.   

    加个Timer定时器,然后在Form的Close事件里做些处理
      

  2.   

    在激发form1关闭事件时,让timer激活,然后四秒后关闭form1
      

  3.   

    干嘛要睡一会呢?
    直接
    form2.showsth()
    然后继续关闭不就行了
      

  4.   

    thread.sleep(4000)
    这个你用哪里了?  可以的呀
    你在form_closing事件中用呢
      

  5.   

    在Form的Close事件里thread.sleep(4000) 
    应该可以啊。
      

  6.   

    formClosing事件
    {
        if(timer1.enable = false
        {
            e.cancel = true 取消关闭事件
            messagebox.show("4秒后关闭!")
            timer1.Enable = ture;
         }
    }timer1_ticket事件
        this.close()
      

  7.   

    如果希望让form1的关闭事件,能够通知给form2,就需要这么些代码:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace WindowsFormsApplication2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                Form2 frm2 = new Form2();
                this.FormClosing += new FormClosingEventHandler(frm2.RecievedForm1CloseEvent);
                frm2.Show();
            }
        }
    }
    然后在form2中处理form1的关闭事件
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace WindowsFormsApplication2
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }        public void RecievedForm1CloseEvent(object sender, FormClosingEventArgs e)
            {
                this.label1.Text = "form1正在关闭中......";
                if (MessageBox.Show("你真的要关闭form1吗?","请确认!",MessageBoxButtons.OKCancel,MessageBoxIcon.Question)!= DialogResult.OK)
                {
                    e.Cancel = true;
                    return;
                }
            }
        }
    }