Click here to Skip to main content
15,031,680 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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.

C#
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);


Kindly send me the answer.

Thanks ,
Viswanathan.M
Posted
Updated 7-Sep-11 22:17pm
v2

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)
   
Comments
Mehdi Gholam 8-Sep-11 4:30am
   
My 5
You have to add you lable control to GroupBox. Like this

C#
GroupBox1.Controls.Add(lblobj);
   
Comments
Viswanthan.M. 8-Sep-11 4:46am
   
ya,its working..one more doubt..how can i change the modifier of the controls dynamically?
Suresh Suthar 8-Sep-11 4:58am
   
You can just declare your control as any other variable like
public Lable lblObj= new Lable();

This link will help you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900