We're going to create some customized property pages to make our control easier to use for the programmer. Custom Property Pages not only make our control look professional, but they make it very easy for the user to set up our control. Property Pages are a snap to add. Before we use another Wizard to create the page for us, let's take a look at the finished product. Then as we walk through the steps, you will already have a good feel for what the end result looks like.
When the user draws our control on the form, by clicking on our control to give it focus and pressing F4 they bring up the Properties box:
Notice that the first choice is (Custom) with an ellipsis. Pressing this will bring up our Custom Property Page that we will build - our own customized property page. The user can now simply add the values for these two properties to set up our control for use:
We have really made it easy to use. Now when the user enters a property, the Apply button automatically becomes enabled. Pressing this will write the property to the
and keep the form displayed. Pressing OK writes the property and dismisses the Property Page. But I think you will agree that this is a nice touch. We place the only two properties the user must enter on a single page.PropertyBag
If the user does not select (Custom) but instead clicks on either of these properties in the control property box, our customized Property Page is automatically displayed.
Now that we've seen the end result that we're aiming for, let's build those custom property pages.
1. If the Property Page Wizard is not currently on your drop down menu of Add-Ins, select Add-In Manager… from the Add-Ins menu. This will display a dialog box of all available Wizards loaded on your PC. Click the VB 6 Property Page Wizard. Be sure the Loaded/Unloaded check box in the Load Behavior frame is checked. Press OK and it will now be available from the Add-Ins menu.
2. Now that the Property Page Wizard is loaded, select it from the Add-Ins menu and click Next> to move on from the Introduction screen. Press Add to add a new property page. We will call this page VBDBDataControl:
Click OK to add the page. Then press Next>.
The next screen in the Wizard permits us to select the properties we wish to add on our property page. The Wizard reads our ActiveX
file to see which properties we are reading and writing. Remember when we added these two properties to the dbCtl.ctl
? Well, the Wizard now knows that these are persistent properties, so it offers them as options to display on our new property page:PropertyBag
3. Select both of the available properties by clicking the >> button:
This will now make them available on our new property page.
4. After the properties are added, click Finish to dismiss the Wizard. You will get a Property Page Wizard Summary Report.
5. Now take a look at your Project Explorer:
Notice that a new folder, Property Pages, has been added. Within this folder is our single page, VBDBDataControl. More sophisticated controls can contain multiple property pages. However, we were able to limit the number of properties to two that the user must enter.
6. Double-click on the property page, VBDBDataControl, to display it. VB provides some default widths for our property text boxes. Resize the text boxes as shown:
We know that the
can be long, so by making this text box wider the user will be able to see the entire string at a glance.ConnectionString
That's it. The Wizard now has linked in our customized Property Page and it will automatically be available for the users who program using our data control. VB has some additional standard Property Pages that could be used if necessary. For example, if you wanted to permit your users to change the color of the control, you would write a
property and select the BackColor
Property Page. Bring up the Properties window for your data control and click on PropertyPages:StandardColor
It makes sense for our control only to have our own customized Property Page. However, if you build other controls, you can simply select any of the predefined Property Pages available here and VB 6.0 will automatically add them for you.
For our next finessing measure, let's add an informative About box to our control.