Creating new objects, buttons etc..

Levu

Well-known member
Joined
Jun 13, 2007
Messages
51
Location
Norway - Drammen
Programming Experience
1-3
Anyone got any good guides on how to make new buttons, and controlls by programming? Not just the drag and drop..

would realy help, thanks
 
Are you talking about how to create controls at run time? If so then it's no different to any other objects. You simply invoke a constructor and set the appropriate properties, e.g.
VB.NET:
Dim b As New Button

b.Location = New Point(50, 100)
b.Text = "OK"
You use the AddHandler statement to attach event handlers, which you can read about in the MSDN library:
VB.NET:
AddHandler b.Click, AddressOf ButtonClick
Finally, to display the control on the form you add it to the Controls collection:
VB.NET:
Me.Controls.Add(b)
If you open the designer code file for any form you can see similar code.
 
Back
Top