Using Controls

[Previous] [Next]

So far, you've learned how to use the Field Chooser to add controls to a form. The Field Chooser automatically binds the control to the appropriate field. You can also add controls to your form manually.

You can set properties for the controls you use on forms, such as change the name, change the display properties, and bind the control to an Outlook field. You access the properties for a control via the Properties dialog box: in design mode, right-click on the control and select Properties. From the Properties dialog box, shown in Figure 4-7, you can select options that control the behavior and appearance of the different Outlook controls. The following sections describe some of the Outlook controls and how to manipulate some of their properties.

Figure 4-7. The Properties dialog box.

Accessing Controls from the Control Toolbox

The Control Toolbox, shown in Figure 4-8, provides an easy way for you to pick controls when you design your forms. To launch the Control Toolbox in Outlook, enter into design mode and choose the Control Toolbox option from the Form menu. You can customize the Control Toolbox to assist you in designing forms more quickly. For example, you could add the controls that you drag and drop most often onto the toolbox. You can customize the Control Toolbox in the following ways:

  • Add pages to the toolbox.
  • Rename the pages.
  • Move controls from one page to another.
  • Add other controls, such as ActiveX controls.
  • Copy modified controls or groups of controls from your custom forms to the toolbox for use on other forms.

To add controls to the toolbox from an Outlook form, select the controls that you want to add and then drag and drop the controls onto the toolbox. You can select individual controls or groups of controls.

click to view at full size.

Figure 4-8. The Control Toolbox and a group of controls that have been dragged and dropped to the toolbox.

Renaming Controls

By default, when you add a control to an Outlook form, Outlook automatically assigns a name to it—for example, Outlook would assign the name TextBox1 to a new TextBox control. However, it is good practice to rename the control to a name that better describes its function. Just make sure you give it a name different from the name of the field the control is bound to. By giving the control and the field different names, you can avoid some confusion when writing your applications. Place an abbreviation at the beginning of the control to identify the content type. For example, if you add a TextBox control that holds the job status information for a potential job candidate, you might want to precede the control name with the abbreviation txt to indicate the type. Therefore, a sample TextBox name would be txtJobStatus. When extending your form with VBScript, you need to use the name of the control inside your script.

Assigning Captions

The Caption property is available to only some of the Outlook controls: CheckBox, CommandButton, Frame, Label, OptionButton, MultiPage, and ToggleButton. You set the Caption property via the Properties page. Setting the Caption property for each control has a different effect. For the Label and CommandButton controls, the Caption property specifies the text that appears in the control. For the MultiPage control, the Caption property applies to each page of the control and specifies the text that appears as the tab name.

You can use the Caption property to set up accelerator keys (single-character shortcuts) for your controls. For example, you might assign the ALT-A accelerator key combination to a CommandButton control named Automatically Populate Fields. To turn any letter in the text of the caption into an accelerator key, place an ampersand (&) before the letter.

For the Outlook controls that do not support captions, such as the TextBox control, you can create individual Label controls for identification. For example, suppose you created a TextBox control that takes the name of a user as input. You could create a label control with the text User Name: and position it to appear before the TextBox control.

Setting the Font and Color

Outlook allows you to set the font and color of your controls. The colors you set for your controls can be relative to the colors that your users have set for their system. For example, you can set the background color for a control to be the same as the system window color, which the user establishes.

Using different properties for a control creates unique effects in your application. For example, to create shading, set the background color of a label control and then layer it behind other controls on your form. This effect is shown in Figure 4-9.

NOTE
If you want to provide shading for a whole page of your form, use the advanced Properties window of the form to set the BackColor property rather than add a label that stretches across the entire page. To learn how to set the advanced properties for a control or a page, see the section titled "Setting Advanced Control Properties" later in this chapter.

click to view at full size.

Figure 4-9. Set the background color of a Label control to provide shading on a certain portion of the form.

Establishing Display Settings

Outlook provides six settings for the display of a control:

  • Visible
  • Enabled
  • Read Only
  • Resize with Form
  • Sunken
  • MultiLine

With the first three of these properties, you can make your controls behave differently depending on the user accessing the form.

Binding Controls

Sometimes, when you create a new control, you will want to bind the control to an existing field rather than create a new one. To do so, in design mode, right-click the desired control, select Properties, click on the Value tab, and click Choose Field. From the drop-down list, choose the field you want to bind to your control. Since this control is bound to a field, any changes made to the information in the control will be reflected in the field.

Setting Initial Values

You can set initial values for the controls on your form that are either static or calculated via the Value tab of the Properties dialog box, as shown in Figure 4-10. You can also select whether Outlook should use your initial value only when a user is composing an item based on the form, or automatically whenever any of the values used to calculate the initial value change or a user opens the form. For example, you can set Outlook to automatically use your name as the initial value in the Subject field of your form. Whenever a user composes or reads the form, your name will always appear in the Subject field. When calculating initial values, you can use the same functionality used in formula fields. To take advantage of initial values, you must bind your control to an Outlook field.

Figure 4-10. Using a formula in the initial value of a control. This formula calculates the total sale price based on the total number of items times the unit price per item.

Requiring and Validating Information in Fields

You can require that any field or any control bound to a field have a value. If the user does not enter any information in the field and attempts to close, save, or send the form, Outlook returns an error message that tells the user a value is required.

Outlook can also compare the value the user has entered to the validation criterion you specify. This criterion can range from simple text to complex formulas. If the validation fails, you can specify the message to appear. This message should be used to tell the user what the expected values are in the field. For example, if you create a TextBox control on your form that is supposed to have a number value greater than 0 in it, you can use a validation formula to make sure that the user does not enter negative numbers in the field. If the user attempts to enter a negative number, your custom message can ask the user to enter a positive number in the field. You set these properties via the Validation tab of the Properties dialog box.

Built-In Outlook Controls

Outlook provides 14 built-in controls that you can add to your forms, each of which provides unique functionality. The following sections introduce these built-in controls, with the exception of the ScrollBar control.

NOTE
In addition to the 14 built-in controls, you can also use ActiveX controls. We'll discuss ActiveX controls in the section titled "Using Custom or Third-Party Controls" later in the chapter.

Label Control

Use the Label control to display descriptive text such as titles, captions, company logos, or other identifying information. For example, you would use a Label control to identify a text box or to display read-only information. The only time you typically bind a Label control to a field is when you want to just display a field value. Figure 4-11 shows a timecard application where a user enters the number of hours worked each day. The Label control displays the total number of hours worked.

Figure 4-11. A timecard application that uses a Label control to display the total number of hours worked.

NOTE
You can display pictures inside of Label controls. However, you cannot crop or size the picture unless you use an Image control, which is described later in this chapter.

TextBox Control

Use the TextBox control to display or gather information from a user, gathering information being the more common use. You could use the TextBox control on a customer survey form to gather comments. If you bind the TextBox control to a field, the information entered by the user is saved in that field. Figure 4-12 shows some TextBox controls on a form.

click to view at full size.

Figure 4-12. TextBox controls on an Outlook form. These TextBox controls are combined with Label controls to gather information from a user.

The TextBox control is a highly customizable control. You can govern its functionality by setting specific properties on it. For example, you can make a TextBox control automatically adjust its size to fit text entered by the user. You can also add multiline functionality so that users can enter more than one line of text in the TextBox control. You can enable or disable the AutoSize, MultiLine, and WordWrap properties for a TextBox control by right-clicking on a placed control and selecting the Advanced Properties option.

WARNING
Avoid using the AutoSize property when using a TextBox control that already has WordWrap and MultiLine enabled. When the TextBox control is empty, the size of the control will appear only 1 character wide and 1 character high. Further, when the user adds text to the control, the control will automatically resize itself to one long line of text rather than split the text into multiple lines.

ListBox Control

The ListBox control displays multiple values, of which users can select one or more. A ListBox control offers you two different presentation styles:

  • Each item in the ListBox appears on a separate row, and the user can select items by highlighting one or more rows.
  • Items are presented as option buttons or check boxes. For option buttons or check boxes to appear, the ListBox control must be bound to a Keywords field.

If you set the MultiSelect property for the ListBox control on the advanced Properties window to 1 - Multi, the user can select multiple items in the ListBox. When a user selects multiple items in the ListBox, the selections are entered in the field as comma-separated values. You can create views that group or sort by these different values.

You create a list of values in a ListBox control in two ways:

  • Right-click on the ListBox control that is placed on the form, select Properties and click on the Value tab. Click the New button, and create a new field that has a type of Keywords. After creating a new field, enter the desired values in the Possible Values box. You must separate the fields with a semicolon. Do not include quotes around your text unless you want these quotes to appear in the ListBox control. Figure 4-13 shows where you set possible values for a ListBox control.
  • Establish the values programmatically at run time.

click to view at full size.

Figure 4-13. Setting the possible values for a ListBox control. You can see the check boxes that appear when the ListBox control is bound to a Keywords field and the MultiSelect property is set to 1 - Multi.

ComboBox Control

A ComboBox combines the features of a ListBox control and a TextBox control, so it enables you to provide a list from which the user can select an item and a text box into which a user can type information.

You add possible values in the drop-down list of a ComboBox control in the same way you add them for the ListBox control. You can specify the list type on the Value tab of the Properties dialog box, in the List Type drop-down list. Here are the List Type options:

  • Dropdown, to allow the user to type new text into the control
  • Droplist, to force the user to select a value from the drop-down list

Figure 4-14 shows how properties can be set for a ComboBox control.

click to view at full size.

Figure 4-14. This ComboBox allows users to type in the text portion of the control because the List Type drop-down list is set to Dropdown.

CheckBox and ToggleButton Controls

Use the CheckBox and ToggleButton controls to give the user a choice between two values, such as on or off, yes or no, or true or false. You should bind the CheckBox and ToggleButton controls to a Yes/No field type for the control to work properly.

OptionButton Control

The OptionButton control is identical to the CheckBox and ToggleButton controls in that it gives the user two choices, but it differs from them in that a group of OptionButton controls are mutually exclusive. For example, on a helpdesk form, OptionButton controls could be associated with possible operating systems users are running, such as Microsoft Windows 2000 Professional, Microsoft Windows 2000 Server, or Microsoft Windows NT, as shown in Figure 4-15. You can bind all of the OptionButton controls to the same field—for example, the txtUserOS field. The value of the txtUserOS field will be the value of the currently selected OptionButton control. You set the value for an OptionButton control on the Value tab.

Figure 4-15. A set of OptionButtons grouped together with a Frame control. OptionButton controls provide mutually exclusive options to users.

You can group OptionButton controls together using containers, such as the Frame control or MultiPage control. Figure 4-15 showed a Frame control being used to group the OptionButton controls. When you bind one of the OptionButton controls in the group to a particular field, the other controls automatically bind to that same field. Be careful to drag and drop the OptionButton controls onto a container in your form, not onto the form page—Outlook automatically groups all OptionButton controls on the form page together, which might not produce the desired functionality.

You can also group your OptionButton controls by using the GroupName property, which identifies related OptionButton controls on a form. To set the GroupName property for an OptionButton control, in design mode, right-click on the OptionButton control that you want to modify and select Advanced Properties. Double-click on the GroupName property, and type in a unique name for the group. Click Apply, and repeat the steps for all the other OptionButton controls in your group.

NOTE
If you want to create a group of OptionButton controls on a TabStrip control, you have to use the GroupName property. The TabStrip control is not a container.

Frame Control

Frame controls are used to create groups of related controls. As you saw earlier, a frame can hold a group of mutually exclusive OptionButton controls, but it can hold other types of controls as well. Add controls to and remove controls from a frame by dragging and dropping them.

CommandButton Control

CommandButton controls provide custom functionality when clicked by the user, so you write the script that responds to its click event. The click event is the only event for the CommandButton control. For information on writing scripts in Microsoft Outlook forms, see Chapter 5.

MultiPage and TabStrip Controls

The MultiPage control and TabStrip control are similar in that they offer multiple pages, or tabs, for holding information. The distinction is that every page in a MultiPage control is its own form, so you can customize the layout and background colors of each page as well as place unique controls on them. The TabStrip control must contain the same controls on every page, so you do not have flexibility with layout. Use it if you want a single layout for your data that you can then map a unique set of data to. Figure 4-16 shows how the MultiPage control is used for the Account Tracking application we'll look at in Chapter 6.

click to view at full size.

Figure 4-16. The MultiPage control for the Account Tracking application provides several pages of information.

To add controls to and remove controls from a MultiPage or TabStrip control, drag and drop them. To customize a page of a MultiPage control, enter design mode, right-click the desired tab, and select Insert, Delete, Rename, or Move. The Insert command always places the page as the last tab, so to position the tab correctly after you've added it, use the Move command.

SpinButton Control

The SpinButton control has arrows that allow you to increment or decrement a number. It accepts custom script—you choose whether or not to write it. If you want to use the SpinButton control to increment and decrement values in another control such as a TextBox control, rather than write script, simply bind the data to the same field for both controls. Figure 4-17 shows the SpinButton control and TextBox control bound to the same field.

Figure 4-17. Both the SpinButton and TextBox controls are bound to the same field. The user can use the spin button to increment and decrement the value in the TextBox control.

Image Control

The Image control displays an image on your form, as shown in Figure 4-18. The Image control supports the following file formats:

  • .bmp
  • .cur
  • .gif
  • .ico
  • .jpg
  • .wmf

Here are some of the properties you can set in the advanced Properties window for the Image control:

  • AutoSize. Control automatically grows or shrinks based on the size of its associated graphic.
  • Picture. Specifies the picture to display.
  • PictureAlignment. Determines where the image appears in the control if the height and width of the Image control is greater than the size of the image.
  • PictureSizeMode. Lets you clip, stretch, or zoom the image.
  • PictureTiling. Creates picture tiles that fill all available space in the Image control.

click to view at full size.

Figure 4-18. An Image control on an Outlook form displays a picture.

You can also set the Picture property for the Image control by using VBScript in your Outlook form. By setting the Picture property programmatically, you can dynamically change the graphic contained in the Image control.

Using Custom or Third-Party Controls

There might be times when the built-in controls of Outlook do not meet the requirements of your application. In these cases, you can extend the Outlook forms environment by adding controls, such as ActiveX controls. You can create these controls by using development tools such as Microsoft Visual Basic or Microsoft Visual C++, or you can use controls developed by third-party companies. Figure 4-19 shows three ActiveX controls placed on an Outlook form.

click to view at full size.

Figure 4-19. ActiveX controls on an Outlook form.

To add custom controls to your Control Toolbox, in design mode, right-click on the Control Toolbox and select Custom Controls. In the Additional Controls dialog box, check the custom controls you want to add and click OK.

NOTE
For the controls placed on your form to work correctly, they must be available on the computers of your users. Outlook does not automatically distribute ActiveX controls with the form.

When you add one of these controls to your form, you can take advantage of its unique functionality by binding specific properties of the control to Outlook fields, by setting the advanced properties for the control, or by automating the control through VBScript. For example, you can place the TreeView control included with Visual Basic on your form, and then bind the selected node of the tree to your custom text field in Outlook so that you can track which node the user has selected. (You could also capture this information by using a click event handler to place the value in your custom field.)

Usually, you want to bind the default property of the control, typically the value of the control. However, there might be times when you want to bind to other properties in the control. To bind a custom control property to an Outlook field, access the Value tab of the Properties dialog box, select the desired field from the Choose Field drop-down list, and in the Property To Use drop-down list, select the custom property of the control you want to bind the field to.

Different controls support different properties. To learn about the properties of a control, access the help file included with the control or use an object browser, such as the VBA Object Browser, to browse the properties of the control. Using the VBA Object Browser is discussed in Chapter 5.

Setting Advanced Control Properties

There are many times when you need to change the advanced properties of a control on your form, such as the background color of the control or the way the control lists the values contained in it. Below are some of the advanced properties for controls in the advanced Properties window:

  • ForeColor. This property determines the foreground color of the control, which in turn affects any text associated with the control. This text can be inside of the control or the caption of the control. You can either use selected system colors or create your own color scheme for this property.
  • BackColor and BackStyle. These properties determine the background of the control. BackStyle determines whether a control is transparent. BackColor specifies the background color. For this property, you can either use selected system colors or create your own color scheme for this property.
  • BorderColor, BorderStyle, and SpecialEffect. These properties apply to the border of the control. By using these properties, you can specify whether a control has a unique color around its border or whether a control looks sunken into the form or raised off the form. BorderStyle and SpecialEffect are mutually exclusive; when you assign a value to one of these properties, Outlook automatically resets the other.
  • Picture. This property determines the picture on the control. You can set this property for many Outlook controls.
  • ControlTipText. This property determines the short, descriptive text that appears when a user holds his mouse over the control.
  • MousePointer and MouseIcon. These properties are used in conjunction to determine the icon used when the mouse passes over the control. You can set the MousePointer property to one of 16 built-in icons such as the hourglass icon or the arrow with a question mark icon. When you set the MousePointer property to 99 - Custom, the MouseIcon property is used to determine which icon to use. You can specify your own icons in the MouseIcon property.
  • PasswordChar. This property specifies the placeholder character that is displayed in the control in place of the real characters. This property is available only for TextBox controls. You can use this property to provide some protection when users enter sensitive information into the form.

Setting the Tab Order

The tab order determines which control the focus moves to when the user presses either the Tab key or Shift-Tab keys. Setting up a logical tab order for your form makes it easier for users to quickly enter information in the controls. To set the tab order, right-click on the desired page on the form, being careful not to click on the controls, and then select Tab Order. In the Tab Order dialog box, select the various controls from the list box and click the Move Up button or Move Down button to adjust the order. You can select more than one control at a time by holding down the Ctrl key and clicking on the desired controls.

NOTE
Label controls are included in the Tab Order dialog box. However, at run time, these controls are not included in the tab order.

Layering Controls on a Form

By using the layering capabilities of Outlook forms, you can create dynamic visual effects. For example, you can shade different areas of the forms by creating colored label controls that serve as the background for other controls on the form. Outlook layers controls by using the z-order (depth) axis, which determines whether controls are in front of or behind other controls. To layer the controls on your Outlook form, in design mode, select the control or controls you want to adjust the order for. From the Layout menu, select Order and then select the desired placement option.



Programming Microsoft Outlook and Microsoft Exchange
Programming Microsoft Outlook and Microsoft Exchange, Second Edition (DV-MPS Programming)
ISBN: 0735610193
EAN: 2147483647
Year: 2000
Pages: 184

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