add control through code

1qaz2wsx7

Member
Joined
Aug 16, 2007
Messages
17
Programming Experience
Beginner
I have another problem:
I want to create a label (or a textbox) using code,
i did it like that:
Dim label1 As Label= New Label
label1.Location = New Point(300, 300)
label1.Name = "Label1"
label1.Size = New System.Drawing.Size(300, 300)
label1.Text = "This is a form !"
label1.BackColor = Color.Blue
label1.Visible = True
label1.Show()

But its not working, the label is not shown on the screen,
What is the problem ?

Thanks.
 
Last edited by a moderator:
Add it to the Controls collection of the container you it in, for example forms: Me.Controls.Add(label1)
 
Hi :)

Thanks its working.


I have a problem, after i make this control using a code,
i want that this control will be at the front of the screen, because i noticed
its behind evrything, How can i do that ?

(for some reason it doesnt have the 'settoplevel' property)

Thanks.
 
BringToFront method could be it.
 
Back
Top