C#动态添加控件到窗体不显示

时间:2014-06-26 19:13:10   收藏:0   阅读:291

在FormLoad里面添加控件时,用this.Controls.Add()方法向窗体里面动态添加控件,调试,一直不显示,后来发现原来窗体上有一个groupbox覆盖了整个窗体,其实控件已经添加上去了,只是被遮盖了。

后面改为this.groupBox1.Controls.Add(),把控件添加到groupbox里面就不会被遮盖了

bubuko.com,布布扣
 1 private void UniqueForm_Load(object sender, EventArgs e)
 2         {
 3             if (pFlag == 1)
 4             {
 5                 Label lbllevel = new Label();
 6                 lbllevel.Text = "请设置级数:";
 7                 lbllevel.Location = new System.Drawing.Point(38, 95);
 8                 lbllevel.AutoSize = true;
 9                 lbllevel.Visible = true;
10                 txtLevel = new TextBox();
11                 txtLevel.Name = "txtLevel";
12                 txtLevel.Location = new System.Drawing.Point(121, 92);
13                 txtLevel.Height = 21;
14                 txtLevel.Width = 150;
15                 txtLevel.Visible = true;
16                 this.groupBox1.Controls.Add(lbllevel);
17                 this.groupBox1.Controls.Add(txtLevel);
18             }
19 }
View Code

 

C#动态添加控件到窗体不显示,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!