Changing the Form s Design-Time Properties

     

Changing the Form's Design-Time Properties

Forms (and all the control objects you can add to a form) have an extensive list of properties that you can manipulate by entering or selecting values in the Properties window. (Recall that you display the Properties window by activating View, Properties Window or by pressing F4.)

graphics/note_icon.gif

Besides modifying form properties at design time, you can also modify many of the properties at runtime by including the appropriate statements in your VBA procedures. I talk about this in greater detail later in this chapter (see the section "Using a Form in a Procedure").


For a form, there are more than three dozen properties arranged into seven categories (in the Properties window, activate the Categories tab to see the properties arranged by category, as shown in Figure 13.1), as described in the next few sections.

The Appearance Category

The properties in the Appearance category control the look of the form:

BackColor ” Sets the color of the form's background. For this and all the color properties, you select a color by first clicking the drop-down arrow to display a color menu. In this menu, you can either choose a predefined color from the System tab or a built-in color from the Palette tab.

BorderColor ” Sets the color of the form's border. Note that for this property to have any effect, you have to assign a border to the form using the BorderStyle property.

BorderStyle ” Choose fmBorderStylSingle to apply a border around the form. Use fmBorderStyleNone for no border.

Caption ” Specifies the text that's displayed in the form's title bar.

ForeColor ” Sets the default color of text used in the form's controls.

SpecialEffect ” Controls how the form appears relative to the form window (for example, raised or sunken).

The Behavior Category

The properties in the Behavior category control aspects of how the user interacts with the form:

Cycle ” Determines what happens when the user presses Tab while the focus is on the last control in the form. If this property is set to fmCycleAllForms and the form has multiple pages (see "Tab Strips and MultiPage Controls," later in this chapter), focus is set to the first control on the next page. If this property is set to fmCycleCurrentForm , focus is set to the first control on the current page.

Enabled ” Set this property to True to enable the form or False to disable it (this prevents the user from manipulating the form or any of its controls).

RightToLeft ” When True, this property changes the tab order of the form so that pressing Tab moves the highlight among the controls from right to left (instead of the usual left to right).

ShowModal ” Set this property to True to display the form as modal, which means the user won't be able to interact with the underlying application until he or she closes the form.

The Font Category

The Font property determines the default font used throughout the form. When you activate this property, click the ellipsis ( ) button to display the Font dialog box, from which you can select the font, style, size , and effects.

The Misc Category

As its name implies, the Misc category contains a collection of properties that don't fit anywhere else, although almost all of these properties are obscure and can be safely ignored. The one exception in the Name property, which you use to give a name to your form. (You'll use this name to refer to the form in your VBA code, so use only alphanumeric characters in the name.)

tip

graphics/tip_icon.gif

Although you might be tempted to stick with the default form name supplied by VBA (such as UserForm1), your code will be easier to read if you give the form a more descriptive name. Indeed, this advice applies not only to forms, but to all controls.


The Picture Category

In the Picture category, use the Picture property to set a background image for the form. (Again, click the ellipsis button to select a picture file from a dialog box.) The other properties determine how the picture is displayed:

PictureAlignment ” Specifies where on the form the picture is displayed.

PictureSizeMode ” Specifies how the picture is displayed relative to the form:

fmPictureSizeModeClip ” Crops any part of the picture that's larger than the form.

fmPictureSizeModeStretch ” Stretches the picture so that it fits the entire form

fmPictureSizeModeZoom ” Enlarges the picture until it hits the vertical or horizontal edge of the form.

PictureTiling ” For small images, set this property to True to fill the background with multiple copies of the image.

The Position Category

The properties in the Position category specify the dimensions of the form (height and width) and the position of the form within the application window. For the latter, you can either use the StartUpPosition property to center the form relative to the application window ( CenterOwner ) or to the screen ( CenterScreen ), or you can choose Manual and specify the Left and Top properties. (The latter two properties set the form's position in points from the application window's left and top edges, respectively.)

The Scrolling Category

The properties in the Scrolling category determine whether the form displays scroll bars and, if it does, what format the scroll bars have:

KeepScrollBarsVisible ” Determines which of the form's scroll bars remain visible even if they aren't needed.

ScrollBars ” Determines which scrollbars are displayed on the form.

ScrollHeight ” Specifies the total height of the form's scrollable region. For example, if the form's Height property is set to 200 and you set the ScrollHeight property to 400, you double the total vertical area available in the form.

ScrollLeft ” If ScrollWidth is greater than the width of the form, use the ScrollLeft property to set the initial position of the horizontal scroll bar's scroll box. For example, if the ScrollWidth is 200, setting ScrollLeft to 100 starts the horizontal scroll bar at the halfway position.

ScrollTop ” If ScrollHeight is greater than the height of the form, use the ScrollTop property to set the initial position of the vertical scroll bar's scroll box.

ScrollWidth ” Specifies the total width of the form's scrollable region.



Absolute Beginner's Guide to VBA
Absolute Beginners Guide to VBA
ISBN: 0789730766
EAN: 2147483647
Year: 2003
Pages: 146

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net