4
Answers

Using Statement

Shankar M

Shankar M

10y
1.1k
1
Dear Experts,
 
I am using "using" statements to create labels dynamically.So the objects can be disposed after added to flow layout panel. Here is my code.
 The problem is the control created are not added to the flow layout panel.
 
Code :
 
for (int j = 0;j<10 ; j++)
{
using (Label lbl = new Label())
{
lbl.Text = "Label" + j.ToString();
lbl.Name = "Label" + j.ToString();
lbl.Font = new Font("verdana", 6.0f);
lbl.Size = new Size(43, 8);
//lbl.Click +=new EventHandler(lbl_Click);
//flowLayoutPanel1.Margin = new Padding(0, 0, 0, 0);
//flowLayoutPanel1.Padding = new Padding(0, 0, 0, 0);
this.flowLayoutPanel1.Controls.Add(lbl);
}
}
 
Any help appreciated.
 
Thanks, Shankar M
 
Answers (4)