Using Controls


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 ”for example, you can change the name , change the display properties, or 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 choose Properties. In 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 select controls when you design your forms. To launch the Control Toolbox in Outlook, enter design mode and choose Control Toolbox from the Form menu. You can also customize the Control Toolbox. For example, you can add the controls that you use most often to 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

click to expand
Figure 4-8: The Control Toolbox and a group of controls that have been dragged and dropped on the form

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

Renaming Controls

By default, when you add a control to an Outlook form, Outlook assigns a name to it ”for example, Outlook would assign the name TextBox1 to a new TextBox control. However, it is good practice to change the name to one that better describes the control's function. Just be sure the name you choose is 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. You should also 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 txt to indicate the control type ”for example, txtJobStatus . When you extend your form with VBScript, you must use the name of the control inside your script.

Assigning Captions

The Caption property is available for only some of the Outlook controls: the CheckBox, CommandButton, Frame, Label, OptionButton, MultiPage, and ToggleButton controls. You set the Caption property via the Properties page. This property has a different effect for each control. 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. Try to avoid duplicating existing shortcuts, such as ALT-F; otherwise , the accelerator will not perform as expected.

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 create a TextBox control that takes the name of a user as input. You can create a label control with the text User Name: and position it to appear before the TextBox control. Be sure to adjust the tab order (as shown later in this chapter) so your label and the data entry control that it describes are in the correct order.

Setting the Font and Color

Outlook allows you to set the font and color of your controls. The colors you set for controls can be relative to the colors 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.

You can use different properties for a control to create unique effects in your application. For example, to create shading, you can 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.

click to expand
Figure 4-9: Setting the background color of a Label control to provide shading on a certain portion of the form
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 of the form itself, rather than adding 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.

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 who accesses the form.

Binding Controls

When you create a new control, you might want to bind it to an existing field rather than create a new field. To do so, in design mode, right-click on the control, choose Properties, click on the Value tab, and click Choose Field. In the drop-down list, select the field you want to bind to your control. Because this control is bound to a field, any changes made to the information in the control will be automatically 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 specify 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 set the due date for a new item to a week from the current day. 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

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 will return an error message that tells the user a value is required.

Outlook can also compare the value the user has entered to the validation criteria you specify. These criteria can range from simple text to complex formulas. If the validation fails, you can specify the message that will appear. This message should tell the user what the accepted values are for the field. For example, if you create a TextBox control on your form that should contain a number value greater than 0, you can use a validation formula to make sure the user does not enter a negative number 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 on 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.

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

You use a Label control to display descriptive text such as titles, captions, or company logos. For example, you 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 display just a field value. Figure 4-11 shows a timecard application in which a user enters the number of hours worked each day. The Label control displays the total number of hours worked.

click to expand
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 Label controls by using the Advanced Properties of the control. However, you cannot crop or size the picture unless you use an Image control, which is described later in this chapter.

TextBox Control

You use a TextBox control to display or gather information from a user ” generally the latter. You can use a 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. These TextBox controls are combined with Label controls to let users know what type of information they are expected to enter.

click to expand
Figure 4-12: TextBox controls on an Outlook form

The TextBox control is highly customizable. 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 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 specific TextBox control by right-clicking on it and choosing Advanced Properties.

Caution  

Avoid using the AutoSize property when you use a TextBox control that already has WordWrap and MultiLine enabled. If you use this property, 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 having text on multiple lines.

ListBox Control

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

  • Each item in the ListBox appearing on a separate row. The user can select items by highlighting one or more rows.

  • Items presented as option buttons or check boxes. For this to work, the ListBox control must be bound to a Keywords field type. Set the MultiSelect property to single for option buttons, and set it to multi for check boxes.

If you set the MultiSelect property for the ListBox control in 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 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, choose Properties, and click on the Value tab. Click the New button, and create a new field that has a type of Keywords . Enter the desired values in the Possible Values box. You must separate the values with a comma or semicolon. Do not surround your text with quotes unless you want these quotes to appear in the ListBox control. Figure 4-13 shows where to set 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 and ListStyle set to 1 - Option .

    click to expand
    Figure 4-13: Setting values for a ListBox control

  • Establish the values programmatically at run time.

ComboBox Control

A ComboBox control combines the features of a ListBox control and a TextBox control ”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 values to 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    Allows the user to type new text in the TextBox portion of the control or select a value from the drop-down portion of the control

  • Droplist    Forces the user to select a value from the drop-down list

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

click to expand
Figure 4-14: A ComboBox control, which allows users to type in the text portion of the control because the List Type property is set to Dropdown

CheckBox and ToggleButton Controls

You 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 or ToggleButton controls to a Yes/No field type for the control to work properly.

OptionButton Control

The OptionButton control also gives the user multiple choices, but it differs from the CheckBox and ToggleButton controls in that multiple OptionButton controls in a group are mutually exclusive. For example, on a helpdesk form, you can associate OptionButton controls with operating systems that users might be running, such as Microsoft Windows 2000 Professional, Windows 2000 Server, or 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 of the Properties dialog box.


Figure 4-15: A set of OptionButton controls grouped together with a Frame control

You can group OptionButton controls together using containers, such as a Frame control or a MultiPage control. Figure 4-15 shows 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 on your form, not onto the form page ”Outlook automatically groups together all OptionButton controls on the form page, 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 choose Advanced Properties. Double-click on the GroupName property, and type a unique name for the group. Click Apply, and repeat the steps for all the other OptionButton controls in your group.

Note  

Some controls, such as the TabStrip control, appear to contain other controls but actually do not. If you want to create a group of OptionButton controls on a TabStrip control (described later), you must use the GroupName property to distinguish which controls are "on" the TabStrip and which are just on the form.

Frame Control

Frame controls are used to create groups of related controls. You've seen that a frame can hold a group of mutually exclusive OptionButton controls, but it can hold other types of controls as well. You add controls to and remove controls from a frame by dragging and dropping them. When you move the frame on the form, all of the controls within the frame move with it. Be aware that when you delete a frame, all of the controls within the frame are deleted as well. You can also cut and paste controls from the form into the Frame control and vice-versa.

CommandButton Control

A CommandButton control provides custom functionality when a user clicks it. You write the script that responds to the control's click event. The click event is the only event for the CommandButton control. For information on writing scripts in Outlook forms, see Chapter 5.

MultiPage and TabStrip Controls

The MultiPage and TabStrip controls are similar in that they offer multiple pages, or tabs, for holding information. The difference 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. The TabStrip control is appropriate if you want a single layout for your data that you can 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 8.

click to expand
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, you drag and drop them into the control. To customize a page of a MultiPage control, enter design mode, right-click on the desired tab, and choose 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 decide whether 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, you simply bind the data to the same field for both controls. Figure 4-17 shows a SpinButton control and a TextBox control bound to the same field. The user can use the SpinButton to increment and decrement the value in the TextBox control.


Figure 4-17: A SpinButton control and a TextBox control are bound to the same field

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

click to expand
Figure 4-18: Image controls on an Outlook form displaying pictures

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.

You can also set the Picture property for the Image control by using VBScript in your Outlook form. You'll learn about writing script for Outlook in the next chapter. By setting the Picture property programmatically, you can dynamically change the graphic contained in the Image control.

ScrollBar Control

You can use the ScrollBar to allow users to scroll through text or to increment or decrement integer values. The ScrollBar requires coding because it does not automatically associate itself with any other control on the form.

Using Custom or Third-Party Controls

Sometimes the built-in controls in Outlook might 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 expand
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 choose Custom Controls. In the Additional Controls dialog box, select 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. One way to distribute the controls is to make a Web page download for the control and automatically redirect the Web browser or an embedded Web browser control on the form to that Web page. Another approach is to package your ActiveX control as a self-installing program and provide it to your users.

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 you can track which node the user has selected. (You can also capture this information by using a click event handler to place the value in your custom field. You'll learn how to do this in the next chapter.)

Usually, when you bind a control to an Outlook field, it's the default property of the control, typically the value of the control, that you bind. However, sometimes you might want to bind to other properties in the control. To bind a custom control property to an Outlook field, on 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. The Object Browser is discussed in Chapter 5.

Setting Advanced Control Properties

You'll often 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. Here are some of the properties for controls displayed only 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 the control or the caption of the control. You can use selected system colors or create your own color scheme for this property.

  • BackColor and BackStyle    These properties determine the background of the control. BackColor specifies the background color. BackStyle determines whether a control is transparent. For this property, you can use selected system colors or create your own color scheme.

  • BorderColor , BorderStyle , and SpecialEffect    These properties apply to the border of the control. You can use the BorderColor property to specify whether a control has a unique color around its border, and you can use BorderStyle and SpecialEffect to specify whether it looks sunken into the form or raised off the form, respectively. BorderStyle and SpecialEffect are mutually exclusive; when you assign a value to one of these properties, Outlook automatically resets the other.

  • Picture    This property specifies the picture on the control. You can set this property for many Outlook controls.

  • ControlTipText    This property specifies the short, descriptive text that appears when a user holds the mouse over the control.

  • MousePointer and MouseIcon    These properties together 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-and-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 it to provide some protection when users enter sensitive information into the form. An asterisk (*) is a common PasswordChar property value.

Setting the Tab Order

The tab order determines which control the focus moves to when the user presses the Tab key or presses Shift-Tab. 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 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 while clicking 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 ”they automatically forward their tab focus to the next control.

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 whose order you want to adjust. From the Layout menu, choose Order, and then select the desired placement option.




Programming Microsoft Outlook and Microsoft Exchange 2003
Programming MicrosoftВ® OutlookВ® and Microsoft Exchange 2003, Third Edition (Pro-Developer)
ISBN: 0735614644
EAN: 2147483647
Year: 2003
Pages: 227
Authors: Thomas Rizzo

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