Create a control from the code window

Percey

New member
Joined
Feb 10, 2008
Messages
2
Programming Experience
1-3
Create a control from the code window (SOLVED)

I'm looking to create a control without using the design mode. I've looked through the MSDN for the "CreateControl()" method but found nothing that I know how to use.

Just for the sake of the question, I'll say I'd like to create just a simple label control with any name at any location on the form... How should I go about it?
 
Last edited:
A control is just an object like any other, so you create a control like you do any other object:
VB.NET:
Dim lbl As New Label
You can then set the control's properties, the same as you would any other object.

The difference between controls and other objects is that they are displayed on a form so, after all the standard stuff, you need the extra step of adding the control to the form:
VB.NET:
Me.Controls.Add(lbl)
 
Ahh, worked perfectly.

I was missing the
VB.NET:
Me.Controls.Add(lbl)
part..I used
VB.NET:
myLabel.CreateControl()...

Thanks a bunch
 
Back
Top