If you switch to the test Form and exercise the new control you’ll see that it does n quite behave like the standard controls. The custom properties on the Properties window can be set to any value. We need to add some code that will display only valid values for the Text Alignment and Effect properties and limit the user’s choice to valid settings. Figure 16.6 shows the Properties window for the control when the Text alignment property is selected
Some custom properties
may have limited values.
which should be displayed
in a drop-down list such as
A data type that can hold a small number of values is called Enumerated type The Integer Double and other numeric data types are generic and can -numeric values. If your application uses a variable that can take on only a number of integer values you can use the Enumerated data type. The Text Aliment property is such a variable. It can take only one of T days of the week and the months of the year are also examples-of Enumerated types. To create Enumerated data type, you must first.declare the type’s values so that Visual Basic knows which ones are valid. Insert the following Enumerated type declaration at the beginning of the code right after the Option Explicit statement:
This declaration tells Visual Basic that any-variable defined as Align can have the values 0 through 8 (Enumeratd types correspond to numeric values starting with 0). The strings that appear in the declaration are”synonyms of the correspond numeric values which will be displayed in the Properties window. The Square brackets are necessary only if the corresponding strings have embedded spaces (or in general are invalid variable names).
For this to happen, we must change the type of the Text alignment property from Integer to Align (the Enumerated type we just declared). The text Alignment property shouldn’t be an integer but an Enumerated type. Open the FLX Label project group and implement the following changes
1.Select the Use Control open its Code window and at the beginning of the code insert the following type definition:
2. Now change the definitions of the Text Alignment property’s Let and Get procedures so that their type is Align and not Integer. Make the following changes to these two procedures:
Public Property Get Text Alignment() As Align
Text Alignment mL Text Alignment
Public Property Let Text Alignment(By Val New_Text Alignment As
m_Text Alignment – New_Text Alignment
Property Changed ·Text Alignment·
Notice that the validation code in the Property Let procedure is no longer need because the user Can’t select an invalid value for this property in the Properties window If you attempt to assign an invalid value to this property from within your code the command will be ignored without any warnings or error messages. The property will simply not change value. If you attempt to set an enumerated property to an invalid value from within you code a trappable run time error will be generated