C#中 通过代码 把LABEL1放在PANEL里

2024-11-28 14:36:36
推荐回答(1个)
回答(1):

//Panel pan1 Panel pan1 = new Panel(); pan1.Size = new Size(310, 120); pan1.Location = new Point(4, 55); pan1.BackColor = Color.White; pan1.BorderStyle =BorderStyle.FixedSingle; this.Controls.Add(pan1); //Label l1 Label l1 = new Label(); l1.Text = "QQ帐号"; l1.ForeColor = Color.Black; l1.Size = new Size(20, 20); l1.Location = new Point(200, 170); this.Controls.Add(l1); //只是在这里需要修改一下,因为this.controls表示的是Form的控件集合,改成panel1.Controls即可 this.pan1.Controls.Add(this.l1);