namespace WindowsFormsApplication1
{
    public class Form1 
    {
        public Form1()
        {
            InitializeComponent();
        }        private void Form1_Load(object sender, EventArgs e)
        {
            Form2 Form = new Form2();
            Form.Show();
            Form.Activate();
            Application.DoEvents();
            System.Threading.Thread.Sleep(5000);
            Form.Close();
            Form.Dispose();
        }
    }
}
我想让form2的实例显示后停顿5秒,这段代码编译没有错误,可就是不显示form2的实例啊,问题出在哪里呢?

解决方案 »

  1.   

    不要用Sleep吧,加个定时器吧~~
      

  2.   

    你该不是没有创建Form2.cs吧?
      

  3.   

    先启动Form2,在Form2中放一个timer1控件,timer1.Interval = 5000;imer1.Enabled = true;
    在事件timer1_Tick中启动Form1.// 应用程序的主入口点。
    // </summary>
    [STAThread]
    static void Main() 
    {
      Application.Run(new Form2());
    }private void timer1_Tick(object sender, System.EventArgs e)
    {
      timer1.Enabled=false;
      this.Hide();
      Form1 Frm= new Form1();
      Frm.ShowDialog();
    }
      

  4.   

    public frmMain()
            {
                
                System.Threading.Thread showThread = new System.Threading.Thread(new System.Threading.ThreadStart(ShowSplash));
                showThread.Start();
                InitializeComponent();
                showThread.Abort();
                showThread.Join();            showThread = null;
            }
            private void ShowSplash()
            {
                欢迎  huanying = null;
                try
                {
                    huanying = new 欢迎();
                    huanying.ShowDialog();
                }
                catch
                {
                    //MessageBox.Show(e.Message);
                }
                finally { huanying = null; }
            }