Using classes to make instances of form elements

DaBomb

Member
Joined
Oct 13, 2007
Messages
5
Programming Experience
1-3
I can't figure out how (or if) you can use a class to create an element on a form.
I have a set of different commands that each do a certain thing, and each commands has checkboxes, a textbox, and a submit button, maybe in a group box. I would love to be able to simply create a new instance of a command and have it appear on the form, without having to code each one.
Can classes have their own elements on a form and be able to create a new instance? Or should I start coding each one separately...
Sorry if this isn't too clear. I'm trying not to give too much detail while still getting the concept across...
 
OK, so I have this class of whatever, and I want it to contain, let's say, a textbox and a button that makes a messagebox showing the contents of the textbox. Can making a new instance of the class (mybuttonclass = new whatever) add a button and textbox(contained in the class) to the form? And can creating multiple instances of the form add multiple groups of textboxes and buttons?
 
When you call that classes constructor it will run any code you like. So if you declare a new text box in the 'Sub New' (constructor) it will create the textbox, groupbox, anything you like.
 
Create your own UserControl, which contains all the child controls and logic you need. You can then add instances of that UserControl to a form and treat each as a unit.
 
Back
Top