The previous pages of this article contained the code for two versions of an inherited Visual Basic control. This page tells you why the BetterCheckBox version is better.
One of the main improvements is the addition of two Properties. This is something the old class didn't do at all.
The two new properties introduced are
FillColor
and
FillImage
To get a flavor of how this works in VB.NET, try this simple experiment. Add a class to a standard project and then enter the code:
Public Property Whatever
Get
When you press Enter after typing "Get", VB.NET Intellisense fills in the entire Property code block and all you have to do is code the specifics for your project. (The Get and Set blocks aren't always required starting with VB.NET 2010, so you have to at least tell Intellisense this much to start it.)
Public Property Whatever
Get
End Get
Set(ByVal value)
End Set
End Property
These blocks have been completed in the code above. The purpose of these blocks of code is to allow property values to be accessed from other parts of the system.
With the addition of Methods, you would be well on the way to creating a complete component. To see a very simple example of a Method, add this code below the Property declarations in the betterCheckBox class:
Public Sub Emphasize()
Me.Font = New System.Drawing.Font( _
"Microsoft Sans Serif", 12.0!, _
System.Drawing.FontStyle.Bold)
Me.Size =
New System.Drawing.Size(200, 35)
CenterSquare.Offset(
CenterSquare.Left - 3,
CenterSquare.Top + 3)
End Sub
In addition to adjusting the Font displayed in a CheckBox, this method also adjusts the size of the box and the location of the checked rectangle to account for the new size. To use the new method, just code it the same way you would any method:
MyBetterEmphasizedBox.Emphasize()
And just like Properties, Visual Studio automatically adds the new method to Microsoft's Intellisense!
The main goal here is to simply demonstrate how a method is coded. You may be aware that a standard CheckBox control also allows the Font to be changed, so this method doesn't really add much function. The next article in this series, Programming a Custom VB.NET Control - Beyond the Basics!, shows a method that does, and also explains how to override a method in a custom control.

