问题
So I got this program where I got a flowlayoutPanel with some dynamically created panels with the following code:
int xlocation = 5;
for (int i = 0; i < td2.Rows.Count; i++)
{
Panel panel = new Panel();
{
panel.Name = string.Format("{0}", i);
panel.Text = string.Format(i.ToString());
panel.BackColor = Color.White;
panel.Location = new System.Drawing.Point(xlocation, 30);
panel.Size = new System.Drawing.Size(385, 80);
flowLayoutPanel1.Controls.Add(panel);
Label label = new Label();
label.Location = new System.Drawing.Point(15, 10);
label.AutoSize = true;
label.Font = new System.Drawing.Font("Calibri", 13F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
label.ForeColor = System.Drawing.Color.FromArgb(64, 64, 64);
label.Text = string.Format("{0}", td1.Rows[i][1].ToString());
panel.Controls.Add(label);
Label label1 = new Label();
label1.Location = new System.Drawing.Point(15, 30);
label.AutoSize = true;
label1.Font = new System.Drawing.Font("Calibri", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
label1.ForeColor = System.Drawing.Color.FromArgb(64, 64, 64);
label1.Text = string.Format("{0}", td1.Rows[i][2].ToString());
panel.Controls.Add(label1);
Label label2 = new Label();
label2.Location = new System.Drawing.Point(330, 10);
label2.AutoSize = true;
label2.Font = new System.Drawing.Font("Calibri", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
label2.ForeColor = System.Drawing.Color.FromArgb(64, 64, 64);
label2.Text = string.Format("{0}{1}", td1.Rows[i][4].ToString(), " DKK");
panel.Controls.Add(label2);
}
xlocation = xlocation + 85;
}
The problem is that my panels wont fill when resizing my form, when the flowlayoutpanel gets bigger. Any help is much appreciated!
来源:https://stackoverflow.com/questions/65139768/how-to-anchor-and-dock-child-controls-in-a-flowlayoutpanel-control-c-sharp-win