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)
{
}
}
}
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)
{
}
}
}
...全文
相关推荐
c# winform 问题记录器
C#写的问题收集记录器,主要是为了方便自己在公司学习时记录笔记,能查看指定日期内所有解决或未解决的问题。
winform 各类问题的解答
此文件夹里有关于winform的各式问题的解答,包括了界面,版本,线程和多种控件的解答。
winform置顶问题解决.zip
使用WPF嵌入winform控件时,winform控件始终显示在窗口正上方,使用该资源可解决
winform 八皇后问题
winform 八皇后问题! 很值得下载看看!资源免费,大家分享!!
DataGridView c# winform解决排序后行颜色丢失的问题
完全是源码,可以很好地解决C# Winform中对DataGridView 进行排序后,行的颜色,单元格颜色改变了的方法: 在赋数据源时:把 DataGridView1.DataSource=DataTable1,去掉,用我提供的源码的方法,再数据源就可以了: 改成dtToDgv(DataGridView1, DataTable1, 1),非常非常的好


