Hi. I am trying to do a test run of Chapter02Program01. I've added the code and created a label, textbox and button per the instructions. But when I do F5, a blank window is displayed. The label, textbox and button do not even display. I've actually entered a title for the window in the frmMain Text property and resized it but it does not display with the title or the new size.
I am running VS 2013 on Windows 7 (via Bootcamp on a Mac), so I'm not sure if that's the issue. My code is below. Please let me know if I'm missing anything. Thanks.
Code:
using System;
using System.Windows.Forms;
public class frmMain:Form
{
private TextBox txtName;
private Button btnSubmit;
private Label lblName;
#region Windows Code
private void IntializeComponent()
{
}
#endregion
public frmMain()
{
IntializeComponent();
}
[STAThread]
public static void Main()
{
frmMain main = new frmMain();
Application.Run(main);
}
private void InitializeComponent()
{
this.lblName = new System.Windows.Forms.Label();
this.txtName = new System.Windows.Forms.TextBox();
this.btnSubmit = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// lblName
//
this.lblName.AutoSize = true;
this.lblName.Location = new System.Drawing.Point(48, 131);
this.lblName.Name = "lblName";
this.lblName.Size = new System.Drawing.Size(55, 20);
this.lblName.TabIndex = 0;
this.lblName.Text = "Name:";
this.lblName.Click += new System.EventHandler(this.label1_Click);
//
// txtName
//
this.txtName.Location = new System.Drawing.Point(109, 128);
this.txtName.Name = "txtName";
this.txtName.Size = new System.Drawing.Size(192, 26);
this.txtName.TabIndex = 1;
//
// btnSubmit
//
this.btnSubmit.Location = new System.Drawing.Point(307, 124);
this.btnSubmit.Name = "btnSubmit";
this.btnSubmit.Size = new System.Drawing.Size(98, 34);
this.btnSubmit.TabIndex = 2;
this.btnSubmit.Text = "Submit";
this.btnSubmit.UseVisualStyleBackColor = true;
this.btnSubmit.Click += new System.EventHandler(this.button1_Click);
//
// frmMain
//
this.ClientSize = new System.Drawing.Size(835, 586);
this.Controls.Add(this.lblName);
this.Controls.Add(this.txtName);
this.Controls.Add(this.btnSubmit);
this.Name = "frmMain";
this.Text = "Main Form";
this.ResumeLayout(false);
this.PerformLayout();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
frmMain.ActiveForm.Text = txtName.Text;
}
}