Winform问题
两个winform,在一个form里有一个Main()里面用Application.Run(new Form2())首先显示另外一个form,编译后运行总是显示
An exception 'System.NullReferenceException' has occurred in ApplicaitonBrowser.exe.
为什么?
下面是两个form的代码,没有放任何其他的功能
Browser.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Reflection;
namespace ApplicationBrowser
{
/// <summary>
/// Summary description for Browser.
/// </summary>
public class Browser : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Browser()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
[STAThread]
static void Main()
{
Application.Run(new Login());
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Browser";
}
#endregion
}
}
Login.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace ApplicationBrowser
{
/// <summary>
/// Summary description for Login.
/// </summary>
public class Login : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panelBottom;
private System.Windows.Forms.Button buttonOk;
private System.Windows.Forms.Button buttonCancel;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Login()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.panelBottom = new System.Windows.Forms.Panel();
this.buttonOk = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.panelBottom.SuspendLayout();
this.SuspendLayout();
//
// panelBottom
//
this.panelBottom.BackColor = System.Drawing.Color.Gray;
this.panelBottom.Controls.AddRange(new System.Windows.Forms.Control[] {
this.buttonCancel,
this.buttonOk});
this.panelBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panelBottom.Location = new System.Drawing.Point(0, 226);
this.panelBottom.Name = "panelBottom";
this.panelBottom.Size = new System.Drawing.Size(408, 40);
this.panelBottom.TabIndex = 0;
//
// buttonOk
//
this.buttonOk.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.buttonOk.Location = new System.Drawing.Point(240, 8);
this.buttonOk.Name = "buttonOk";
this.buttonOk.TabIndex = 0;
this.buttonOk.Text = "确定";
this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click);
//
// buttonCancel
//
this.buttonCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.buttonCancel.Location = new System.Drawing.Point(320, 8);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.TabIndex = 1;
this.buttonCancel.Text = "取消";
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// Login
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(408, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.panelBottom});
this.Name = "Login";
this.Text = "Login";
this.panelBottom.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void buttonCancel_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
private void buttonOk_Click(object sender, System.EventArgs e)
{
}
}
}