3: Set Properties
Up

The Properties Window is used to establish initial property values for objects.  The drop-down box at the top of the window lists all objects in the current form.  Two views are available:  Alphabetic and Categorized.  Under this box are the available properties for the currently selected object:

In order to refer to a particular property of a particular control, it is necessary to use 'dot notation' - the name of the control is placed first, followed by a dot and then the property. For example, the width property of a commandbutton called cmd1 would be referred to as cmd1.width. Code to set the width of the command button to 1000 would look like this:
            cmd1.width = 1000

Let's look at some properties that are common to the various types of controls:

Name

The first property that you are likely to modify is the control's name. Giving controls meaningful names makes it much easier to write and read the code. The standard convention for naming controls is to use a three letter prefix (depending on the object) followed by a name you assign.  Two good reasons to use these prefixes are:

bulletin alphabetic listings, controls of the same type will be grouped together
bulletit will be obvious form the name of the control what type of control it is

A few of the prefixes are (we’ll see more as we progress in the class):

          Object                    Prefix                     Example

Form                      frm                         frmWatch

Command Button     cmd,                      cmdExit

Label                      lbl                           lblStart, lblEnd

Text Box                 txt                           txtTime, txtName

Menu                      mnu                        mnuExit, mnuSave

Check box               chk                         chkChoice

Note that control names can be up to 40 characters long, must start with a letter, must contain only letters, numbers, and the underscore (_) character.  Names may not contain spaces.

Color

You can select various colors such as backcolor, forecolor and textcolor by clicking the color property and choosing from a palette of colors.

Left, Top, Width, Height, Scalemode, Scalewidth, Scaleheight

These four dimensions fix the position and size of the control. Left and Top fix the position of the top-left corner of the control relative to an origin at the top-left of the form, so coordinates are measured to the right and down. For example a position of (300,500) would be 300 units to the right and 500 units down. Note that this is not the same as in your math class, where coordinates are measured right and UP. The size is given by Width and Height. Note that there are no Bottom or Right properties since this could contradict the other dimensions - is you need to know where the right and bottom edges of the object are you can find them by adding the left+width or top+height values, respectively. Distances on the form are usually measured in an odd unit called a 'twip'. One twip is defined as 1/1440 inch (about 0.00176cm). You can change the Scalemode property of the form if you prefer to work in centimeters or inches, or you can define your own scale using the scalewidth and scaletop properties of the form (you could choose units such that the width of the form equals 100 units, for example).

Text

This property is unique to the textbox control - it is simply the text that appears in the box. This is not the same as the name property, for the user never sees the name of a control, only its label. The name is only used to identify the control in the program's code.

Caption

For controls other than the textbox control, the text that the user sees is called the text property.

ToolTipText

Have you noticed that in many programs you can point at icons or objects and a little note appears to tell you something about the object? Set the tooltiptext property to add this helpful feature to your own programs.

Visible

This property is either true, meaning the control is visible, or false, meaning it is not. Therefore you can make a control disappear while a program is running by using code to set its visible property to false.

Enabled

This property is either true, meaning the control is functional, or false, meaning it is disabled. You can disable a control while a program is running by using code to set its enabled property to false.

Previous Up Next