Introducing control properties

Every control that you add to a UserForm has properties that determine how the control looks and behaves. You can change a control's properties at these two times:

^ At design time — when you're designing the UserForm. You do so manually, using the Properties window.

^ At run time — while your macro is running. You do so by writing VBA code. Changes made at run time are always temporary; they were made to the copy of the userform you are showing, not to the actual userform object you designed.

When you add a control to a UserForm, you almost always need to make some design-time adjustments to its properties. You make these changes in the Properties window. (To display the Properties window, press F4.) Figure 17-2 shows the Properties window, which displays properties for the object selected in the UserForm — which happens to be a CheckBox control.

Figure 17-2:

Use the Properties window to make design-time changes to a control's properties.

Figure 17-2:

Use the Properties window to make design-time changes to a control's properties.

To change a control's properties at run time you must write VBA code. For / if\ example, you may want to hide a particular control when the user clicks a ( MM I check box. In such a case, you write code to change the control's Visible property.

Each control has its own set of properties. All controls, however, share some common properties, such as Name, Width, and Value. Table 17-1 lists some of the common properties available for most controls.

Table 17-1

Common Control Properties

Property

What It Does

Accelerator

The letter underlined in the control's caption. The user

presses this key in conjunction with the Alt key to select

the control.

AutoSize

If True, the control resizes itself automatically based on

the text in its caption.

BackColor

The control's background color.

BackStyle

The background style (transparent or opaque).

Caption

The text that appears on the control.

Value

The control's value.

Left and Top

Values that determine the control's position.

Width and Height

Values that determine the control's width and height.

Visible

If False, the control is hidden.

Name

The control's name. By default, a control's name is based

on the control type. You can change the name to any valid

name, but each control's name must be unique within the

dialog box.

Picture

A graphics image to display. The image must be contained

in a file; it can't be copied from the Clipboard.

When you select a control, that control's properties appear in the Properties window. To change a property, just select it in the Properties window and make the change. Some properties give you some help. For example, if you need to change the TextAlign property, the Properties window displays a drop-down list that contains all valid property values, as shown in Figure 17-3.

When you select a control, that control's properties appear in the Properties window. To change a property, just select it in the Properties window and make the change. Some properties give you some help. For example, if you need to change the TextAlign property, the Properties window displays a drop-down list that contains all valid property values, as shown in Figure 17-3.

Figure 17-3:

Change properties by selecting from a dropdown list of valid property values.

Properties - CheckBoxl

CheckBoxl CheckBox * |

Alphabetic | Categorized |

Heiaht

12.75

HelpContextID

0

Left

18

Locked

False

Mouselcon

(None)

MousePointer

0 - frriMousePointerDefault

Picture

(None)

PicturePosition

7 - frnPicturePositionAboveCenter

SpetialEffect

2 - frnButtonEffectSunken

Tablndex

1

TabStop

True

Tag

TextAlign

2 - frriTextAlignCenter

Top

1 - frnTextAlignLeft

2 - frriTextAlignCenter k

3 - fmTextAlignRight kj

Visible

True

Width

114

wordwrap

True

v

0 0

Post a comment