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
2010-07-21 12:35:31
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
2010-07-21 12:40:13
This is my answer
Snoob
2010-07-21 12:45:31
@tobiasopdenbrouw, I have answered the question. The code could be placed in many places thats is upto them.
Ash Burlaczenko
2010-07-21 15:59:49
@Ash, sure, no problem.
Tobiasopdenbrouw
2010-07-22 07:04:29
+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
2010-07-21 12:37:08
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
2010-07-21 12:38:00