此按钮的代码:
int offsetY = 5;
int x = 0;
int y = 0;
int index = 1;
//Start adds new panel and new label
Panel b = new Panel();
Label la = new Label();
//Adds panel properties
b.Controls.Add(la);
b.Location = new Point(x, y + offsetY);
b.Size = new Size(633, 119);
newhaven.Class1 cl = new newhaven.Class1();
b.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
flowLayoutPanel1.Controls.Add(b);
b.ResumeLayout(false);
//Adds label properties
x = 0;
y = -20;
la.Location = new Point(x,y);
// la.Size = new Size(60, 30);
la.Text = "Hello";
flowLayoutPanel1.Controls.Add(la);
我想打个招呼在面板中
你能帮我吗?
答案 0 :(得分:0)
您几乎完全正确,但是需要注意标签的位置坐标,请确保它们位于面板坐标内。
以下作品:
int offsetY = 5;
int x = 0;
int y = 0;
int index = 1;
//Start adds new panel and new label
Panel b = new Panel();
Label la = new Label();
//Adds panel properties
b.Controls.Add(la);
b.Location = new Point(x, y + offsetY);
b.Size = new Size(633, 119);
//newhaven.Class1 cl = new newhaven.Class1();
b.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
flowLayoutPanel1.Controls.Add(b);
b.ResumeLayout(false);
// Adds label properties -
// commented the co-ordinates and using the same as that of panel
//x = 0;
//y = -20;
la.Location = new Point(x, y + offsetY);
// la.Size = new Size(60, 30);
la.Text = "Hello";
// no need to add the label separately, its inside the panel
//flowLayoutPanel1.Controls.Add(la);