Share via


Visual Basic Concepts

Associating a Property Page with a Property

Sometimes a property is too complicated to set from the Properties window. A property might be an object, such as the Font object, with properties of its own. A property might consist of an array of values, or even a collection of objects — such as a collection of Toolbar buttons.

For example, Figure 10.3 shows how a property page might look for the Behavior property of a hypothetical VirtualVelociraptor control. This page allows cells to be added to and deleted from animation sequences for the control’s various behaviors.

Figure 10.3   A property too complex for the Properties window

Notice that only the tab associated with the property is displayed. If you compare this picture with Figure 10.1, you’ll notice that the page size used by the Property Pages dialog box is smaller in this picture. When multiple pages are displayed, the size of the largest page is used.

Note   If you declare a property of type Font, OLE_COLOR, or Picture, Visual Basic will automatically associate the property with a StandardFont, StandardColor, or StandardPicture page, as described in "Standard Property Pages."

To associate a property page with an individual property

  1. In the Project Explorer window, right-click the UserControl to open the context menu, and select View Code to open the code window.

  2. On the Tools menu, select Procedure Attributes to open the Procedure Attributes dialog box, and click Advanced to expand the dialog box.

  3. In the Name box, select the property you wish to associate with a property page.

  4. Select the desired property page in the Use this Page in Property Browser list, as shown below, then click Apply or OK.

The EditProperty Event

Visual Basic allows you to associate multiple properties with the same property page. You might want to do this if your control has more than one property that uses the same property page layout, or if one property uses part of another property’s layout. In the latter case, you can use the EditProperty event to enable only the necessary parts of the property page.

When the user clicks the ellipsis button for a property that’s associated with a property page, the page receives the EditProperties event in addition to the events it normally receives. You can use the PropertyName argument of the EditProperties event to identify the property whose ellipsis button was clicked.

The EditProperties event gives you the opportunity to do a number of things to the property page, depending on the nature of your control and the complexity of the property being edited. For example, you might:

  • If the property being edited is displayed in a single control on the PropertyPage, set the focus to that control.

  • Enable and disable controls on the property page so that only those fields applicable to the specified property are enabled.

Not Showing Properties in the Properties Window

In some cases, you may not want a property displayed in the Properties window. For example, if displaying a property value requires a time-consuming calculation, the developer who uses your control may be annoyed at the length of time it takes to access the Properties window.

On the Property Attributes dialog, accessible from the Tools menu, select the property you wish to suppress. Click the Advanced button, check "Don’t show in Property Browser," and then click Apply.