The FLEX Label control displays a caption like the standard Label control, so it must provide the Caption and Font properties which let the developer determine the text and its appearance: In addition the FLEX Label control can align its caption The FLEX Label control displays a caption like the standard Label control so it must provide the Caption and Font properties which let the developer determine the text and its appearance: In addition the FLEX Label control can align its caption
TABLE 16.1:The.Settings of the FLEX Label Control’s Text Alignment Property
0 Top Left
1 Top Middle
2 Top Right
3 Center Left
4 Center Middle
5 Center Right
6 Bottom left
7 Bottom Middle
8 Bottom Right
The names that appear under the Description heading are the strings that will appear in the drop-down list of the Text Alignment property.As you have noticed, properties with a limited’ number of settings display a drop-down list in the Properties window.This list contains descriptive names (instead of numeric values)and the developer can select only a valid setting.
Similarly the text effect is manipulated through the Effect property whose settings are Show in Table 16.2.
TABLE 16.2: The Settings of the FlEX Label Control’s Effect Property
1 Carved Light
3 Carved Heavy
4 Raised Light
6 Raised Heavy
like the Text Alignment property the Effect property has a small number of valid settings which will be identified in the Properties window with descriptive names.
In addition to the custom properties the FLEX Label control should also expose the standard properties of a Label-control such as Font Tag Back Color and so on. Developers expect to see standard properties in the Properties window and you should implement them. The FLEX LabeI control doesn’t have any custom methods but it should provide the standard methods of the Label control such as the Move method. Similarly although the control doesn’t raise any special events it must support the standard events of the Label control such as the mouse and keyboard events.
Except for a few custom properties this control must expose the standard functionality of the Label control. Most of the custom control’s functionality exists already and there should be a simple technique to borrow this functionality from other controls rather than implementing it from scratch. And this is indeed the case. Visual Basic provides a wizard which will generate the code for implementing standard members. The ActiveX Control Interface Wizard will generate’the code that implements the standard members and you only have to provide the code for the custom properties.
Designing a Custom Control
To start a new Activex control project follow these steps
1. Choose File > New Project.
2. In the New Project window select the ActiveX Control icon. Visual Basic creates a new project named Project which contains a user Control named User Control.
The initial setup for an ActiveX control project is shown in Figure 16.3 (the names in the project window are different, and I’ll show you immediately how to change them).
Let’s rename the project and the control These two names will be used to register your control in your system, so they should be meaningful. Follow these steps:
1. Select Project in the Project window, ‘and when its properties appear, change the-Name property to FLEX Label.
2. Select User Control in the Project window, and when its properties appear change the Name property to Label 3D.
Every time you place an ActiveX control on a Form it’s named according to the User Control object’s name and a sequence digit. ‘The first instance of the custom control you place on a Form will be named Label 3D1 the next one will be named labeI 3D2 and so on. Obviously it’s important to choose a meaningful name for your user Control object.
A new object was just introduced: the User Control object. As you will soon see the user Control is the “Form” on which the custom control will be designed. It and behaves like a regular VB Form but it’s called a User Control. User- Control objects have additional unique properties that don’t apply to a regular Form but in order to start designing new controls think of them as regular Forms. Whereas the label application aligns and displays the caption on a Form the Label 3D custom ” tom control uses the same code to draw the caption on the User control object (we’ll simply Change all instances of ‘Me” to ”User Control”)
You’ve set the scene for a new ActiveX control. Before we insert even a single line of code we’ll let a Wizard generate as much of the custom control as it can for us. Among other things it will design the control’s structure.
The ActiveX Control Interface Wizard
Now choose Add ins· ActiveX Control interface Wizard to open the wizard This Wizard will guide you through the steps of creating a new Activex control. It Will create the control’s interface (its properties methods and events) and prepare the basic code for It You will have’to provide only the ‘code that draws the caption and a few more features that can’t be automated. The WiZard will take care of the bulk of the work for you. The ActiveX Control Interface Wizard has six windows which are explained next.
If the ActiveX Control Interface Wizard doesn’t appear in the Add-Ins menu select Add-In Manager and in the Add-In Manager dialog box, double-dick the ” entry VB6 ActiveX Control Interface Wizard. The indication Loaded will appear in the Load Behavior column next to the Wizard’s name, as shown in Figure 16.4. If you tile Wizard to load every time you start visual Basic, check the Load on Startup check box Now, click the OK button/ and the add-in’s name will appear in the Add-In menu.
The Add-In Manager
The ActiveX Control Interface Wizard will guide you through the steps of designing the skeleton of a custom Activex control. The Wizard will not add the code to . align or even display the caption but it will create a functional control with most of the standard members of a typical ActiveX control.
The first screen of the Wizard is a welcome, and you can disable it in the future by checking the Skip This Screen in the Future check box. Click the Next button to .start the design of your Control’s user interlace
Selecting Interface Members
The next window of the wizard prompts you to select the standard members of the control. On the left is a list of standard properties, methods, and events that you can include in your custom control. On the right is a list of common members of the user interface, already selected for you. Visual Basic suggests that your control should support these members.
To add a new member select it from the left list and click the button that has a single right-pointing arrow. Add the following members to the custom control:
As you can see I’ve included all the standard properties events and methods you’d expect to find in any control that’s visible at run time. I’ve omitted the data bound properties but the FLEX Label control won’t be connected to a database field. Click the Next button.