我的c# Windows窗体应用程序是空白的

本文关键字:空白 应用程序 窗体 Windows 我的 | 更新日期: 2023-09-27 18:09:09

我正在制作一个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)
{
}
}

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

我的c# Windows窗体应用程序是空白的

frmMain()中,您调用InitializeComonent()(这是空的)而不是调用InitializeComponent()。可能只是打错了

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

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