3: Set Properties
Up

The Properties Window is used to set 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 (a button in this case):

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 text property of a commandbutton called cmd1 would be referred to as cmd1.text. Code to set the text of the command button to 'Click Me' would look like this:
           
cmd1.text = "Click Me"

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.

Colour

You can select various colours such as backcolor and forecolor by clicking the corresponding colour property and choosing from a palette of colours. For the widest range of colours, work with the 'Custom' palette of colours.

Location.x, Location.y, Size.width, Size.height

These four dimensions fix the position and size of the control. Location.x and Location.y 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,200) would be 300 pixels to the right and 200 pixels 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 Size.Width and Size.Height. Distances on the form are measured in pixels - pixels are the tiny squares that make up anything that you see on your computer monitor.

Text

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

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