在winform中有form1和form2
如form1为启动页
怎样从form1中的控件启动form2,并且启动form2的同时将form1关闭(不是隐藏)?

解决方案 »

  1.   

    如果加载的时候就加载的form1的话,你这样的要求不能实现
      

  2.   

    好像是只有隐藏,
    Form2 form2=new Form2();
    form1.hide();
    form2.show();
      

  3.   

     using System;
        using System.Windows.Forms;
        using System.Threading;    class Program {
            [STAThread]
            static void Main() {
                Form f1 = new Form(){ Text = "f1" };
                f1.Click += delegate {
                    f1.Close();
                    Thread t = new Thread(() => {
                        Form f2 = new Form() { Text = "f2" };
                        //f2.ShowDialog();
                        Application.Run(f2);
                    });
                    t.Start();
                };
                f1.ShowDialog();
            }
        }//经尝试,效果上说好象还行,
      

  4.   

    其实方法还有很多,比如 让F1,F2被包含在另一个类里面F1打开F2时通知这个类去做,而打开F2函数里首先关闭(dispose())F1和上面我回复的差不多
      

  5.   

    你可以在form1里的shown事件中进行启动from2 再把自身关闭
    我觉得你怎么说的有点像flash窗体
      

  6.   

    你参考一下这个吧也许对你有帮助: http://topic.csdn.net/t/20050614/11/4080787.html
      

  7.   

        static class Program
        {
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);            LeftFrameTest frm = new LeftFrameTest();
                frm.ShowDialog();
                if (frm.bSign)
                    Application.Run(new Form1());
                else
                    Application.Exit();
            }
        }//======================================================================
    //
    //        Copyright : SHANGHAI HOMEN INTELLIGENT SYSTEM Co.,LTD.
    //        All rights reserved
    //
    //        Filename : LeftFrameTest
    //        Description :
    //
    //        created by 邱在辉 at  2009-12-1 14:17:01
    //
    //======================================================================using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication1
    {
        public partial class LeftFrameTest : Form
        {
            public bool bSign = false;
            public LeftFrameTest()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                this.bSign = true;
                this.Close();
            }
        }
    }
      

  8.   

    在Program类中
    static class Program
    {
    internal static ApplicationContext context = new ApplicationContext(new Form1());
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main()
    {
    Application.EnableVisualStyles(); //Application.SetCompatibleTextRenderingDefault(false);  
       Application.Run(context);
    }
    }然后这样显示窗体:
    Form2 form = new Form2();
    Program.context.MainForm = form;
    form.Show();
    this.Close();就可以将上下文的主窗体设置为新的Form2了,然后关闭form1就不影响程序运行了