Pelo que tens aí, tens que posicionar as labels na localização correcta...
Label lbl = new Label() { Location = new Point(0, 0) };
ou
lbl.Location = new Point(0, 0);
Mas podes fazer isso só com uma label...
lbl.TextAlign = ContentAlignment.MiddleCenter;
lbl.Text += "\n" + "teu texto"; // \n quebra a linha
Também podes escrever directamente no panel..
if (dr.HasRows)
{
Panel p = new Panel() { Size = new Size(100, 150), BackColor = Color.Green };
this.flowLayoutPanel1.Controls.Add(p);
using (Graphics g = p.CreateGraphics())
{
Font font = new Font("Arial", 8f);
float textHeight = g.MeasureString("@", font).Height;
StringFormat format = new StringFormat() { Alignment = StringAlignment.Center };
int count = 0;
while (dr.Read())
{
g.DrawString(dr[count + 1].ToString(), font, Brushes.Black, new PointF(p.Width / 2, count * textHeight), format);
count++;
}
}
}
↧