views:

53

answers:

3

How to create Object (label, button) using Code?

+2  A: 
Dim myButton as new Button  
myButton.width = 100  
myButton.height = 20  
myButton.top = 50  
myButton.left = 50  
Me.controls.add(myButton)  
Ash Burlaczenko
Yes. Given the level of the question, it may be good to also explain where to place this code (in a button click event, for instance, etc.) :)
Tobiasopdenbrouw
This is my answer
Snoob
@tobiasopdenbrouw, I have answered the question. The code could be placed in many places thats is upto them.
Ash Burlaczenko
@Ash, sure, no problem.
Tobiasopdenbrouw
+1  A: 

You create you Label like every other object, set the properties you need and add it to the Controls collection of your form or usercontrol.
I have only a C# example here:

var label = new Label
{
    BackColor = Color.DarkGray,
    TextAlign = ContentAlignment.MiddleCenter,
    Width = 60,
};
label.MouseClick += LabelOnMouseClick;

Controls.Add( label );
tanascius
A: 

Edit: this answer posted before clarification in the original question.

Try information pages such as HOW TO: Dynamically Create Controls in ASP.NET with Visual Basic .NET. But really: also get a book and study this stuff.

Tobiasopdenbrouw
Snoob's first comment to his original question.
Tobiasopdenbrouw