请问我用C#做启动界面
界面的窗体Form1
主窗体Form2
还有个Form3窗体
-----------------------------------------------------------------
static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form2());
        }
--------------------------------------------------------------
Form2:
private void Form2_Load(object sender, EventArgs e)
        {
            Form1 f = new Form1();
            f.ShowDialog();
        }
-----------------------------------------------------------------
Form1:
private void timer1_Tick(object sender, EventArgs e)
        {
            System.Threading.Thread.Sleep(2000);
              //做一些判断操作
            this.Close();
        }我想Form1启动里做一个判断如果Form1里变量A=1则启动完Form3窗体,而不启动Form2窗体,只有A!=1则启动Form2窗体。
我不知道应该怎么写。

解决方案 »

  1.   

    Form1: 
    private void timer1_Tick(object sender, EventArgs e) 
            { 
                System.Threading.Thread.Sleep(2000); 
                  //做一些判断操作 
    if(A!=1)
    {
       Form2 newform2 = new Form2();
       newform2.show();
    }
    else if(A==1)
    {
      Form3 newform3 = new Form3();
      newform3.show();
    }
                this.Close(); 
            } 
      

  2.   

    可能我没有写全。关键是Form1里timer1.interval=1000这样FORM1启动后启动TIME1 里面判断会每秒都执行的
      

  3.   


    你在programmer.cs里面加句话Application.Run(new Form2());然后在
      Form2 newform2=new Form2(); 
      newform2.show(); 
    这个就行了
    PS 貌似这个代码还是我BLOG上的- -。
      

  4.   

    System.Threading.Thread.Sleep(2000);这句话 时休眠2分钟后继续启动线程
      

  5.   

    Form1: 
    private void timer1_Tick(object sender, EventArgs e) 
            { 
                System.Threading.Thread.Sleep(2000); 
                  //做一些判断操作 
    if(A!=1)
    {
       Form2 newform2 = new Form2();
       newform2.show();
    }
    else if(A==1)
    {
      Form3 newform3 = new Form3();
      newform3.show();
    }
                this.Close(); 
            } 
    是出现2次FORM3
      

  6.   

    timer1.interval=1000 
    要把timer控件给停止掉
      

  7.   

    说错了。是FORM2和FORM3都弹出来了。只要弹一个。
      

  8.   

    timer1.Enable = false;
    加上这句话试试
    应该就不会出现多个 Form3了 否则会一直执行下去
      

  9.   

    当A==1结果 FORM2和FORM3都弹出来了 A==1只要弹FORM3
      

  10.   


    当A==1结果 FORM2和FORM3都弹出来了,还是不好用
      

  11.   

                Form1 f1 = new Form1();            if (f1.a == 1)
                {
                    f1.Show();
                }
                else
                {
                    Form3 f3 = new Form3();
                    f3.Show();
                }把Form1中的A作为public 变量 然后用这个试试
      

  12.   

            private void timer1_Tick(object sender, EventArgs e)
            {
                System.Threading.Thread.Sleep(1000);            Form1 f1 = new Form1();            if (f1.a == 1)
                {
                    f1.Show();
                }
                else
                {
                    Form3 f3 = new Form3();
                    f3.Show();
                }            timer1.Enabled = false;
            }
      

  13.   


    晕。你忽略了
    Form2: 
    private void Form2_Load(object sender, EventArgs e) 
            { 
                Form1 f = new Form1(); 
                f.ShowDialog(); 
            } 
    不管怎么样只要Form1.close() form2肯定show();
      

  14.   


    那简单 在Form1.Close事件里 加 Form2.Show的代码就行了 只要关闭Form1就会触发Close事件那么Form2肯定会Show的
      

  15.   

    你先启动Form2?然后去判断Form1的变量?那Form1没启动你怎么执行Form1的事件?
      

  16.   

    我觉得 你应该第一次运行应该时 启动Form1而不是Form2然后在Form1中判断变量是否满足条件 更具条件去启动相应的窗体
      

  17.   

    那意思Form1还是窗体启动界面的窗体。最后给他隐藏掉吗?要是想不出来更好的办法只能这样了。
      

  18.   

    System.Threading.Thread.Sleep(2000);
                timer1.Enabled = false;
                if (a == 1)
                {
                    Form3 f3 = new Form3();
                    f3.Show();
                }
                if (a != 1)
                {
                    Form2 f2 = new Form2();
                    if (f2 == null || f2.IsDisposed)
                    {
                        f2.Show();
                    }
                    else
                    {
                        f2.Activate();
                    }
                }貌似不能回复了 直接给你留言了 改了下你先前的语句
    要先判断是否已经启动了Form2 有的话就激活窗体 没有就启动 这样就不会启动多个Form了
      

  19.   

    Form1: 
    private void timer1_Tick(object sender, EventArgs e) 
            { 
                System.Threading.Thread.Sleep(2000); 
                  //做一些判断操作 
    if(A!=1) 

      Form2 newform2 = new Form2(); 
      newform2.show(); 

    else if(A==1) 

      Form3 newform3 = new Form3(); 
      newform3.show(); 

                this.Close(); 
            } 
      

  20.   

    我的需求是三个窗体F1,F2,F3
    F1为启动的界面窗体,F2为主窗体
    我现在要启动程序后弹出界面窗体F1,加载一些信息,其中判断的是a==1就启动F2。a!=1就启动F3,我现在使用的是 Application.Run(F2)。
      

  21.   

    System.Threading.Thread.Sleep(2000); 
     这就是线程吗?
      

  22.   

    if(A!=1)
    {
       Form2 newform2 = new Form2();
       newform2.showDialog();
    }
    else if(A==1)
    {
      Form3 newform3 = new Form3();
      newform3.showDialog();
    }
      

  23.   


                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                string strMsg = string.Empty;
                frm_Loading objfrm_Loading = new frm_Loading();
                objfrm_Loading.Show();
                if (!objfrm_Loading.StartTest(ref strMsg))
                {
                    objfrm_Loading.Close();
                    frm_Error.show(strMsg);
                }
                else
                {
                    frm_Mdi objfrm_Mdi = new frm_Mdi();
                    frm_Login objfrm_Login = new frm_Login(objfrm_Mdi);
                    objfrm_Loading.Close();
                    Application.Run(objfrm_Login);
                }简单的启动判断,你参考下