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:

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

1 At run time — while your program is running. You do so by writing VBA code.

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.

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 example, you may want to hide a particular control when a check box is checked by the user. In such a case, you would 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.

Table 17-1 (continued)

Properly

What It Does

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.

Figure 17-3:

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

Properties - OptionBulion? □ptionBiitton2 OptiünButton Alphabetic | categorised |

Mouselcon

(None)

MousePointer

0 - fmMousePüinterDefault

Picture (None)

PicturePosition

7 - fmPicturePositionAboveCenter

SpecialEffect

2 - fmButtonEffectSunken

Tablndex 1

Tab5top

True

Tag

TextAlign

2 - fmTextAlignCenter| ▼

Top

1 fmTextAlignLeft

TripleState

2 - fmTextAlignCenter k

3 - fmTextAliqnRiqht

Visible

True

Width

73.5

WordWrap

True

0 0

Post a comment