我创建了一个窗体Form1,把代码写好后,可以运行,看到窗体结果。
如果我要新创建一个窗体Form2,并且将这个Form2设为启动项,要如何设置?另外,Form2窗体,有个确定按钮,我想点击后,Form2这个窗体退出,进入到Form1窗体,要如何编写?
我用了this.close(),确定以后直接推出了,Form1窗体出不来,虽然我在前面也加了Form1.show()

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;namespace WindowsApplication4
    {
        static class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form2());
            }
        }
    }program.cs的文件
      

  2.   

    1.找到Programm.cs
    -- static class Program
        {
            /// <summary>
            /// 應用程式的主要進入點。
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new frmmain());
            }
        }
      

  3.   

    1、
    在Program.cs中 
    //Application.Run(new Form1());
    Application.Run(new Form2());2、
    private void button1_Click(object sender, EventArgs e)
            {
                this.Hide();
                new Form2().Show();
            }
      

  4.   

    2.
    Form1 frm=new Form1();
    frm.show();
    this.close();
      

  5.   

    首先你要确定一个主窗体并且只能有一个。在确定你的启动窗体,启动窗体启动后hide()隐藏,主窗体show()出来
    上面都说了,我说说也许你会遇到,你把主窗体关闭后程序并没有真正关闭。
    你在主窗体closed事件里加句Application.Exit();就可以了