Using C# 2005, I am trying to create labels at run-time using an array. The code below WITHOUT the array does work without run-time errors:
I get this error ONLY at run-time: object reference not set to an instance of an object if I use the code below which uses an ARRAY to create the labels.Code:namespace sud { public partial class sud : Form { private Label labelTest = new Label(); public sud() { InitializeComponent(); } private void sud_Load(object sender, EventArgs e) { this.labelTest.Size = new System.Drawing.Size(50, 50); this.labelTest.Location = new System.Drawing.Point(40, 40); this.labelTest.Name = "cellTest"; this.labelTest.Text = "Test"; this.Controls.Add(labelTest); } } // end partial class: sud } // end namespace: sud
Suggestions?Code:namespace sud { public partial class sud : Form { private Label[] labelTest2; public sud() { InitializeComponent(); } private void sud_Load(object sender, EventArgs e) { this.labelTest2 = new Label[10]; this.labelTest2[0].Size = new System.Drawing.Size(50, 50); this.labelTest2[0].Location = new System.Drawing.Point(40, 40); this.labelTest2[0].Name = "cellTest"; this.labelTest2[0].Text = "Test"; this.Controls.Add(labelTest2[0]); } } // end partial class: sud } // end namespace: sud



LinkBack URL
About LinkBacks


