How to Anchor and Dock Child Controls in a FlowLayoutPanel Control - C# winforms

旧时模样 提交于 2021-01-29 11:34:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!