I have made a custom UserControl i Vb.net (windows application).
How can I add this dynamically to a form?
A UserControl is essentially just another class. It inherits from Control, so you can do all kinds of things you do with controls, but otherwise it's just a class. Thus, to add the usercontrol dynamically to your form you'd do the following:
Dim X As New MyControl()
Me.MyGreatTabPage.Controls.Add(X)
. You can also add it directly to your form too, because a form is also a container.X.Location
and X.Size
.Remember that each instance you create with New MyControl()
will be a separate MyControl. Don't make the mistake of repeatedly creating new controls and placing them over each other somehow. Create and place the control once. Assign it to a member variable to your form, and when you need to work with it, use this variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With