Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My C# Windows Form Application is blank?

Tags:

c#

I'm Making A windows form application , And everytime I Excute it , All i see is a blank form , My project is named frmMain.cs and this is the header that i use :

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)
{

}
}

I also have a habit that i delete program.cs and frmMain.Designer.cs because i dont need them in my program , Does that have anything to do with my problem ? Help Please!

like image 775
Yousef Abu Zahra Avatar asked Jan 13 '23 16:01

Yousef Abu Zahra


2 Answers

In frmMain() you're calling InitializeComonent() (which is empty) instead of calling InitializeComponent(). Probably just a typo.

like image 195
Felix Avatar answered Jan 17 '23 14:01

Felix


Your code is fine. Just a small typo

public frmMain()
{
    // In your constructor change 'IntitializeComonent' to 'InitializeComponent'
    IntitializeComonent();
}
like image 44
Patrick D'Souza Avatar answered Jan 17 '23 15:01

Patrick D'Souza