Run the test project and check out the operation of the Property Pages generated by the Wizard: This is a good point to add a few more controls on the Text Properties tab which will allow developers to set the other custom properties. The finished Property Page should look like the one shown in Figure 16.12
The Property Page with the
FlEX label control’s custom
properties
Open the Property Page in design mode and add two Combo Box controls and the matching Label controls on top of them. Adjust their size and specify a nice font and size for all the controls.
Now you are ready to adjust the code. The two Combo Box controls must be populated with the valid setting for the two properties. The best place to insert the initialization code is in the page’s Initialize event.
Initializing the Caption Properties Page
Private Sub PropertyPage_Initialize()
Combol.AddItem “Top Left”
Combol.Addltem ‘Top Middle”
Combol.AddItem ‘Top Rjght’
Combol.AddItem ‘Center Left”
Combol.Addltem “Center Middle’
Combol.AddItem “Center Right”
Combol.AddItem “Bpttom Left’
Combol.Addltem ‘Bottom Middle”
Combol.Addltem “Bottom Right”
Combo2.Addltem ‘None’
Combo2 -.Addltem ‘Carved Light’
Combo2.Addltem ‘Carved’
Combo2.Addltem ‘Carved Heavy’
Combo2.AddItem “Raised Light’
Combo2.Addltem “Raised”
Combo2.Ad Item ‘Raised Heavy’
End Sub
Now we must revise the Selection Changed event’s code. We must add the statements to initialize the two Combo Box controls that correspond to the two new properties. Enter the following code in the Property Page’s Selection changed event handler.
Inltializing the Combo Box Controls
Private Sub PropertyPage_SelectionChanged()
txtCaption.Text SelectedControls(O).Caption
Combol.Listlndex – SelectedControls(O).TextAlignment
Combo2.Listlndex – SelectedControls(O).Effect
End Sub
Next you must update the Changed variable from within the events that signify a new selection in the two Combo Box controls. Since the Combo box controls don’t allow the entry of new values the selection can only change with the Click event so add the following subroutines in the Property Page’s code window
Private Sub Combol_Click()
Changed – True
End Sub
Private Sub Combo2_Click()
Changed – True
End Sub
The last step is to revise the Apply changes event so that it applies the current settings of the Combo Box controls to the custom control. Here is the code that implements the Apply button.
Applying the Changes
Private Sub PropertyPage_ApplyChanges(}
SelectedControls(O).CaptiQn – txtCaption.Text
SelectedCoritrols(O).TextAlignment .Combo1.ListIndex
SelectedControls(O).Effect – Combo2.Listlndex
End Sub
You can now switch to the test Form and check out the operation of the Property Pages. As you can see Property Pages aren’t new objects; they are regular VB Forms on which you can place all kinds of controls and do all kind of neat tricks as long as you observe a few rules inserted in the code by the Wizard:
1. Set the Changed property to True each time a property changes value and you want the Apply button enabled.
2.Update the control’s property by using the expression Selected Controls(O) .property Name in which the property Name variable is an actual property name.
3.Initialize the properties each time the user switches to a new Property Page from within the Property Page Selection Changed event
If you look up the Properties window for the User Control object you will see that its Property Pages property is set to 4 to indicate that four Property Pages wadded. Click the ellipsis button to display the Connect Property Pages dialog be shown in Figure 16.13.To exclude a page from the control clear the box in front 0 -its name.
.Visual Basic’s standard
Property Pages are dis·
played in this dialog box.
along With the custom
page we designed or the
FlEX Label control.
Building a custom ActiveX control isn’t a big deal after all The ActiveX Control Interface Wizard takes care of many details for you. It up a skeleton for the control’s code and you supply the code that actually does something ‘presumably something that other controls can’t do). The code you supply is the type of code you would write for any VB application. There are however a differences between
developing regular applications and developing controls. The more you familiarize yourself with these differences the better equipped you will develop ActiveX controls. The following section focuses on these differences. ‘