List box

Place a List box on the form as in Figure 14-5. Using the Properties window, set the properties shown in Table 14-1. Note that the TabIndex property determines not only the order that the controls are visited as the user hits the Tab key, but also determines which control has the initial focus. Since we want the initial focus to be on the list box, we set its tab index to 0.

Table 14-1. Nondefault Properties of the ListBox Control




We should also note that, in general, there are two places in which a control property can be set: in the Properties window at design time or using code during run time. Some properties should be (or must be) set at design time, whereas others can only be set at run time. However, most properties can be set at either time.

As a simple example, a control's Visible or Enabled property is often set during run time, in response to actions by the user. For instance, we may want to disable a command button labeled Print until the user has selected an object to print from a list of objects. Setting the Enabled property of a command button whose name is PrintButton is easily done:

PrintButton.Enabled = False

In general, the choice of where to set a given property of a control is partly a matter of taste. I favor setting properties in code because it tends to make the code more complete and thus more readable. It can also make changing properties simpler. However, some fundamental properties, such as Name and Caption, are best set at design time.

Was this article helpful?

0 0

Post a comment