如何在c#.net Windows应用程序的groupbox控件内动态创建标签控件? [英] how can create label control dynamically inside a groupbox control in c# .net windows application?

查看:391
本文介绍了如何在c#.net Windows应用程序的groupbox控件内动态创建标签控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何在c#.net Windows应用程序的GroupBox控件内部动态创建Lable控件.我使用以下代码.但是它将在组框控件下显示标签控件.

Hi,

How can create Lable control dynamically inside a GroupBox control in c# .net windows application.. I use the following code. But it will display a label control under the group box control.

Label lblobj = new Label();
 lblobj.Text = "Adult";
 lblobj.Font = new Font(lblobj.Font, lblobj.Font.Style | FontStyle.Bold);
 lblobj.BackColor = Color.Transparent;
 lblobj.ForeColor = Color.White;
 lblobj.AutoSize = true;
 lblobj.Location = new Point(610, 323);
 this.Controls.Add(lblobj);



请给我答案.

谢谢,
Viswanathan.M



Kindly send me the answer.

Thanks ,
Viswanathan.M

推荐答案

,您需要将标签添加到groupBox的控件集合中,而不是表单(调用this.controls.add withina方法int他的表单类会将其添加到表单控件集合中,因为在这种情况下,"this"就是表单)
you need to add your label to the groupBox''s control collection not the form''s (calling this.controls.add withina method int he form class will add it to the form control collection as, in that context, ''this'' is the form)


您必须将标签控件添加到GroupBox中.像这样

You have to add you lable control to GroupBox. Like this

GroupBox1.Controls.Add(lblobj);


这篇关于如何在c#.net Windows应用程序的groupbox控件内动态创建标签控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆