Application.Run(new Land());
将Land()改成你想要启动的窗体的构造函数。

解决方案 »

  1.   

    看看
    public static void Main()中的代码,思考一下,就可以想出方法了。
      

  2.   

    在MainForm的load事件中实现化登录窗口,不然mainForm不会启动消息泵。
      

  3.   

    各位老大,我要的不是这样的效果,我的意思是:一开始只启动Loginform ,通过验证后再出现Mainform,好多应用软件都是这样的呀,就象QQ似的,一开始只是个登录界面,通过验证后再出现主界面的,谢谢了,这个问题困惑我好久了!
      

  4.   

    在VB里面,可以通过 工程属性 -->通用 -->启动对象 设定,启动对象是个下拉框,里面包括这个工程的所有form,选定哪一个,运行时就先启动那一个form.
      

  5.   

    源码如下:Form1:using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Threading;namespace WindowsApplication7
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null;
    private static Form1 MainForm;
    Form2 chilForm;

    public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    }



    /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(292, 273);
    this.Name = "Form1";
    this.Text = "Form1";
    this.Load += new System.EventHandler(this.Form1_Load); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    MainForm = new Form1();
    Application.Run(MainForm);
    } private void Form1_Load(object sender, System.EventArgs e)
    { ThreadStart ts = new ThreadStart(ShowForm2);
    Thread t = new Thread(ts);
    t.Start(); }
    private void ShowForm2()
    {
    chilForm = new Form2(this);
    chilForm.ShowDialog();

    }

    }
    }
    Form2:using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;namespace WindowsApplication7
    {
    /// <summary>
    /// Form2 的摘要说明。
    /// </summary>
    public class Form2 : System.Windows.Forms.Form
    {
    private System.ComponentModel.IContainer components = null;
    private Form1 MainF; //此为主窗体的句柄 public Form2(Form1 MainForm)
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    MainF = MainForm;
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    // 
    // Form2
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(292, 273);
    this.Name = "Form2";
    this.Text = "Form2";
    this.Load += new System.EventHandler(this.Form2_Load);
    this.Closed += new System.EventHandler(this.Form2_Closed); }
    #endregion private void Form2_Load(object sender, System.EventArgs e)
    {
    MainF.Visible = false; //主窗体隐藏
    } private void Form2_Closed(object sender, System.EventArgs e)
    {
    MainF.Visible = true;//主窗体显示
    }
    }
    }
      

  6.   

    方法二:private void Form1_Load(object sender, System.EventArgs e)
    { chilForm = new Form2();
    chilForm.ShowDialog();

    }
      

  7.   

    这是主菜单的Load事件,打开Form2后,如果验证不能通过,就用Application.Exit();关闭程序。上面的那个太复杂,没必要用。
      

  8.   

    非也,找到你目前启动窗口,里面有下面一段话:
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    }
    你把它“剪切”到你想要的窗口中去,注意,将Form1修改成对应的窗口名称即可。
      

  9.   

    再补充一点,假如你想用form2启动,修改成:
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form2());
    }
    响应“确定”按钮后:
    Form1 myForm=new Form1();
    myForm.ShowDialog();
      

  10.   

    在VB里面,可以通过 工程属性 -->通用 -->启动对象 设定,启动对象是个下拉框,里面包括这个工程的所有form,选定哪一个,运行时就先启动那一个form.
      

  11.   

    static void Main() 
    {
    frmLogin f = new frmLogin();
    if (f.ShowDialog() == DialogResult.OK)
    {
    Application.Run(new frmMain());
    }
    else
    {
    f.Close();
    }
    }