繁体   English   中英

我的C#Windows表单应用程序是空白的?

[英]My C# Windows Form Application is blank?

我正在创建一个Windows窗体应用程序,每次我执行它时,我看到的只是一个空白表单,我的项目名为frmMain.cs,这是我使用的标题:

using System;
using System.Windows.Forms;

public class frmMain : Form
{
private TextBox txtYear;
private Button btnCheck;
private Button btnClose;
private Label label1;
#region windows code
private void IntitializeComonent()
{
}
#endregion
public frmMain()
{
    IntitializeComonent();
}
[STAThread]
public static void Main()
{
    frmMain main = new frmMain();
    Application.Run(main);
}


 private void InitializeComponent()
{
    this.label1 = new System.Windows.Forms.Label();
    this.txtYear = new System.Windows.Forms.TextBox();
    this.btnCheck = new System.Windows.Forms.Button();
    this.btnClose = new System.Windows.Forms.Button();
    this.SuspendLayout();
    // 
    // label1
    // 
    this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    this.label1.Location = new System.Drawing.Point(25, 24);
    this.label1.Name = "label1";
    this.label1.Size = new System.Drawing.Size(98, 20);
    this.label1.TabIndex = 0;
    this.label1.Text = "Year To Test: ";
    this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
    // 
    // txtYear
    // 
    this.txtYear.Location = new System.Drawing.Point(129, 24);
    this.txtYear.Name = "txtYear";
    this.txtYear.Size = new System.Drawing.Size(100, 20);
    this.txtYear.TabIndex = 1;
    // 
    // btnCheck
    // 
    this.btnCheck.Location = new System.Drawing.Point(25, 93);
    this.btnCheck.Name = "btnCheck";
    this.btnCheck.Size = new System.Drawing.Size(75, 23);
    this.btnCheck.TabIndex = 2;
    this.btnCheck.Text = "Leap Year?";
    this.btnCheck.UseVisualStyleBackColor = true;
    // 
    // btnClose
    // 
    this.btnClose.Location = new System.Drawing.Point(154, 93);
    this.btnClose.Name = "btnClose";
    this.btnClose.Size = new System.Drawing.Size(75, 23);
    this.btnClose.TabIndex = 3;
    this.btnClose.Text = "&Close";
    this.btnClose.UseVisualStyleBackColor = true;
    // 
    // frmMain
    // 
    this.ClientSize = new System.Drawing.Size(284, 262);
    this.Controls.Add(this.btnClose);
    this.Controls.Add(this.btnCheck);
    this.Controls.Add(this.txtYear);
    this.Controls.Add(this.label1);
    this.Name = "frmMain";
    this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
    this.Text = "Determain a Leap Year";
    this.Load += new System.EventHandler(this.frmMain_Load);
    this.ResumeLayout(false);
    this.PerformLayout();

}

private void frmMain_Load(object sender, EventArgs e)
{

}
}

我也有一个习惯,我删除program.cs和frmMain.Designer.cs因为我在我的程序中不需要它们,这与我的问题有什么关系吗? 请帮助!

frmMain()你调用InitializeComonent() (它是空的)而不是调用InitializeComponent() 可能只是一个错字。

你的代码很好。 只是一个小错字

public frmMain()
{
    // In your constructor change 'IntitializeComonent' to 'InitializeComponent'
    IntitializeComonent();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM