Hello
Have a
Panel
and:
string a = "2223232223323222";
char[] chars = a.ToCharArray();
for (int i = 0; i < chars.Count(); i++)
{
Label l = new Label();
l.Text = chars[i].ToString();
this.MyPanel.Controls.Add(l);
l.Top = i * l.Height;
}
or you can do it without
Panel
:
this.Controls.Add(l);
If I were you, I would create a method to figure out the accurate coordinate for
Label
s
private void Form1_Load(object sender, EventArgs e)
{
string a = "2223232223323222";
char[] chars = a.ToCharArray();
for (int i = 0; i < chars.Count(); i++)
{
Label l = new Label();
l.Text = chars[i].ToString();
this.MyPanel.Controls.Add(l);
SetCoordinate(l, i);
}
}
private void SetCoordinate(Label lable, int i)
{
}
But:
If You have many
Label
s in your
Form
, then tag them.
Set their Tags to 0, 1, 2, 3 and ...
Then:
private void Form1_Load(object sender, EventArgs e)
{
string a = "2223232223323222";
char[] chars = a.ToCharArray();
for (int i = 0; i < chars.Count(); i++)
{
Label l = FindLabel(i);
if (l == null)
continue;
l.Text = chars[i].ToString();
}
}
private Label FindLabel(int i)
{
foreach (Control c in this.Controls)
{
if (c.Tag == null)
continue;
int k = 0;
if (!int.TryParse((c.Tag).ToString(), out k))
continue;
if (c is Label && k == i)
return (Label)c;
}
return null;
}