ADO.NET Programming in Visual Basic .NET By Steve Holzner, Bob Howell
Table of Contents
Chapter 11. Creating Your Own Data Control
We will create our data control by subclassing a UserControl. This is a base class from which all visual controls derive. The UserControl class provides a visual drawing space upon which other controls may be placed. It also provides many of the properties and methods you would expect any control to have. In some ways, it is similar to a form. The difference is that the control must be hosted. That is, it must reside on a container . This container may be a form, or another UserControl.
To cover all of the bases, we will be creating what we call a compound control, or a control made up of a group of existing controls. There is another type of control called a painted control. In this type, the control author is responsible for fully creating the visual interface graphically. These controls typically derive from the Control class and are beyond the scope of this book.
VB 6 If you have created controls in VB 6 you have a head start with .NET UserControls. In many ways, VB 6 UserControls were more complex to develop than VB .NET controls. Since VB .NET supports full inheritance and since all IDE designers generate real VB code that you can see, silly things like PropertyBags, the extender object, and the ambient object go away. Property values that are set in the IDE Property window are simply assigned during form initialization. It's right there in the code. We no longer have to worry about persistence; it's automatic. All controls are now compiled into plain .dll files. There is no longer an .ocx file extension for custom controls. If you've programmed in VB long enough, you know that there was no difference between an ActiveX .dll and .ocx. The extension is just a convention used to distinguish visual components from nonvisual ones. I've even used some controls that were compiled as . dlls , probably just to draw the ire of Microsoft.