Share via


Visual Basic Concepts

Using Standard Control Property Types

The code examples in the related topic "Exposing Properties of Constituent Controls" show the use of the standard types Font and OLE_COLOR to create properties that use standard, system-supplied property pages, which the user can access with the ellipsis button in the Properties window.

Whenever possible, use the standard data types and enumerations provided by Visual Basic as data types of your control's properties. This makes life easy for your users, by presenting consistent property value choices in the Properties window.

Standard Enumerations

The following code uses the standard enumeration for the MousePointer property.

Public Property Get MousePointer() As _
      MousePointerConstants
   MousePointer = UserControl.MousePointer
End Property

Public Property Let MousePointer(ByVal NewPointer As _
      MousePointerConstants)
   UserControl.MousePointer = NewPointer
   PropertyChanged "MousePointer"
End Property

When the MousePointer property appears in the Properties window, it will have the same enumeration as the MousePointer properties of other controls.

You can use the Object Browser to determine what enumerations are available in the Visual Basic type libraries.

Note   The purpose and importance of PropertyChanged are discussed in "Adding Properties to Controls," earlier in this chapter.

Standard Data Types

Visual Basic provides four standard data types of special interest to control authors.

OLE_COLOR

The OLE_COLOR data type is used for properties that return colors. When a property is declared as OLE_COLOR, the Properties window will display a color-picker dialog that allows the user to select the color for the property visually, rather than having to remember the numeric equivalent.

An example of the use of OLE_COLOR can be found in "Exposing Properties of Constituent Controls."

OLE_COLOR is treated internally as a Long.

OLE_TRISTATE

The OLE_TRISTATE data type is used for three-state check boxes. If you're authoring a control with check box functionality, declare its Value property as OLE_TRISTATE.

OLE_TRISTATE is an enumeration with the following values:

  • 0 - Unchecked

  • 1 - Checked

  • 2 - Gray

OLE_OPTEXCLUSIVE

If you're developing a control with option-button functionality, use the OLE_OPTEXCLUSIVE data type for the Value property of your control. This will cause your control's Value property to behave like that of the intrinsic OptionButton control. That is, when instances of your control are grouped, and the user clicks an unselected control instance, the currently selected instance's Value is automatically set to 0 (thus unselecting the button), and the Value of the clicked instance is set to 1.

This behavior is handled by the container. The container checks the Value property for each control it contains, and groups those that are of type OLE_OPTEXCLUSIVE.

Note   You must use the Procedure Attributes dialog box to make the Value property the default property, in order for the control host to enable the behavior described.

OLE_OPTEXCLUSIVE is handled as a Boolean type internally.

OLE_CANCELBOOL

Use this data type for an event argument that allows the user to cancel the event. For example, the standard KeyPress event passes a Cancel parameter as its last parameter. If the user sets this parameter to False, the event is canceled.

OLE_CANCELBOOL is handled as a Boolean type internally.