Many times we want to stylize our form elements but modifying the properties of each form element can only take us so far. In many cases, their is also a need to make a control act in a certain way, but should only be changed once and reflected application-wide. I'll discuss a few ways you can make your OWN controls or extend the current controls for the features and functionality you actually deserve
User controls can be created with whatever elements you like. They can be added by right-clicking the project, and adding a new user control. At this point you are a blank slate, and you can add whatever elements (including other user controls) to your user control. You can even add your own properties which are then viewed and executed real time when you add the to a form. It's pretty cool when you "compile" and you see your own custom control in the toolbar
For example, Create a user control, add 5 textboxes and add this to the code of the User Control.
Code:
Public Class UserControl1
Private _TextboxBackgroundColor As Color
Public Property TextBoxBackgroundColor() As Color
Get
Return _TextboxBackgroundColor
End Get
Set(ByVal value As Color)
_TextboxBackgroundColor = value
TextBox1.BackColor = value
TextBox2.BackColor = value
TextBox3.BackColor = value
TextBox4.BackColor = value
TextBox5.BackColor = value
End Set
End Property
End Class Then hit the compile button and watch how it now appears in your toolbar. Drag your new user control onto a form and notice in your properties window that you have available "TextBoxBackgroundColor" property now. Modify it and see that all 5 textboxes change for the control... Now, you are probably asking why would we do this (besides being freekin sweet). Because it extracts the control and now you can use this control everywhere. When the client decides that only 4 of the 5 textboxes should have that color... then it is only one change and it occurs application-wide.
The next lessons to come will discuss the ability to override controls using their events and how to inherit the already-built controls to make shnazzy looking form controls
