1. Home
  2. Computing & Technology
  3. Visual Basic
More Customizing VB.NET Controls
Page 3 - How the NorseBox works
 More of this Feature
• Part 1: More Customizing VB.NET Controls
• Part 2: The NorseBox Code
• Part 4: The NorseBox in VB 6 ?
 
 Join the Discussion
Have you customized a VB.NET tool?
Tell Us About It!
 
 Related Resources
• A First Introduction to VB.NET Controls
The first article on this topic

 

Norseman solved problem number 1 by simply using the properties of the CheckBox that are inherited and calculating the arguments passed to the CenterSquare object (an instance of the GDI+ Rectangle object) that is created in the class. The "magic numbers" that are left (2, 12, 5, 9 and 9) are constants in any CheckBox. The IIF keyword may not be familiar to some, but it was also a feature of VB 6 and hasn't changed.

Problems 2 and 3 introduce a whole new topic, however: Creating new properties in the class. This is something the old class didn't do at all and also something that is done completely differently in VB.NET as compared with VB 6.

The two new properties introduced are

  • FillColor

and

  • FillImage

The main thing that has changed in VB.NET Properties is the use of the Get and Set keywords. In Visual Basic 6.0, you use the Property Get, Property Let, and Property Set statements to get and set property values. These are no longer supported in VB.NET. 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

Press Enter --

VB.NET responds by filling in the entire Property code block and all you have to do is fill in the actions.

    Public Property Whatever()
        Get

        End Get
        Set(ByVal Value)

        End Set
    End Property

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, Norseman 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 NorseBox class:

    Public Sub Emphasize()
        Me.Font = New System.Drawing.Font( _
            "Microsoft Sans Serif", 14.0!, _
            System.Drawing.FontStyle.Bold)
        Me.Size = New System.Drawing.Size(200, 60)
    End Sub

A statement like

MyCheckBox.Emphasize()

will create this result:

The Big NorseBox

And just like Properties, the method is automatically added to Microsoft's Intellisense:

Intellisense

Norseman does good work with a bee in his bonnet!

Next page > Part 4: The NorseBox in VB 6 ? > Page 1, 2, 3, 4

Explore Visual Basic

More from About.com

  1. Home
  2. Computing & Technology
  3. Visual Basic

©2008 About.com, a part of The New York Times Company.

All rights reserved.