Creating Outlook 2007 Form Regions using Visual Studio Tools for the Office System (3.0)

Summary: Learn how to create a Microsoft Office Outlook 2007 form region by using Microsoft Visual Studio Tools for the Microsoft Office system (3.0).

Office Visual How To

Applies to: 2007 Microsoft Office System, Microsoft Office Outlook 2007, Microsoft Visual Studio 2008, Microsoft Visual Studio Tools for the Microsoft Office System (3.0)

Steve Hansen, OfficeZealot.com

September 2007

Overview

Microsoft Office Outlook 2007 offers a way for developers to customize the Outlook 2007 user interface using elements called form regions. Using form regions, you can extend Outlook 2007 items such as mail, contact, or task items. Because form regions can display in the Reading Pane, you can build interesting add-ins that display context-sensitive data in addition to the content of the selected Outlook 2007 item. Microsoft Visual Studio Tools for the Microsoft Office system (3.0) features an Outlook Form Region designer that significantly simplifies the development of Outlook 2007 form regions.

Code It

If your form region is simple, creating it requires little code or effort on your part.

The following procedure shows you how to create a simple Outlook 2007 form region.

To create an Outlook 2007 form region

  1. Start Microsoft Visual Studio 2008.

  2. On the File menu, point to New, and then click Project. The New Project dialog box appears.

  3. Under Project Types, expand Visual C#, and then expand Office.

  4. Select 2007, and then select Outlook Add-In. Name the add-in TestFormRegion.

  5. In Solution Explorer, select the TestFormRegion project. (Press CTRL+ALT+L if Solution Explorer is not visible.)

  6. Press CTRL+SHIFT+A to add a new item.

  7. In the Add New Item dialog box, select Outlook Form Region, and then click Add.

  8. Select the Adjoining option, and then click Next.

  9. Name the form region Test Form Region, and click Next.

  10. In the final dialog box, accept the default selection (Mail Message), and then click Finish.

  11. From the Toolbox window, drag a Label onto the design surface of the form region. (Press CTRL+ALT+X if the Toolbox is not visible.)

  12. Right-click the design surface of the form region, and select View Code.

  13. Modify the FormRegionShowing method as follows.

    NoteNote
    The following code example contains line breaks to facilitate online viewing. You must remove the line breaks for the code to work.
  14. Press F5 to run the project in debug mode.

  15. After Outlook 2007 starts, notice that you can see the Test Form Region in the Reading Pane when you view mail items. Also, notice that Label1 reflects the e-mail address of the current item.

Read It

To develop custom form regions in earlier versions of Visual Studio Tools for Office, you design the form region in Outlook 2007. Then, you create a manifest file, implement the FormRegionStartup interface in an Outlook 2007 add-in, add a registry key that specifies the location of the manifest, create a form region class to wrap the form you created in Outlook 2007, and override the RequestService method in your add-in to return your form region class.

Visual Studio Tools for the Office system (3.0) handles all of these details for you. As a result, developing Outlook 2007 form regions closely resembles the process of creating a standard Windows form or user control.

When you add an Outlook Form Region to your project using Visual Studio Tools for the Office system (3.0), you actually add a Microsoft.Office.Tools.Outlook.FormRegionControl to your project. By default, when you add an Outlook Form Region to your project, Visual Studio Tools for the Office system (3.0) adds stubs for three event handlers: FormRegionInitializing, FormRegionShowing, and FormRegionClosed.

FormRegionInitializing occurs when Outlook 2007 determines that your form region should be associated with the current item (whether you select the item in an Explorer window and display it in the Reading Pane or open it in an Inspector window). This event traces back to the GetFormRegionStorage member on the Outlook.FormRegionStartup interface. If you want to show or hide your form region, implement the logic in the FormRegionInitializing event handler. To prevent the form region from showing, set e.Cancel to true. Visual Studio Tools for the Office system (3.0) creates the FormRegionInitializing event dler for you. You can find the event handler within the Form Region Factory region. This region is collapsed by default.

FormRegionShowing occurs before Outlook 2007 displays the form region. This event traces back to the BeforeFormRegionShow member of the Outlook.FormRegionStartup interface. FormRegionShowing initializes any controls on the form interface.

FormRegionClosed occurs after the form region closes. Visual Studio Tools for the Office system (3.0) adds this event. Use the FormRegionClosed event handler to perform clean-up tasks such as saving any changes to the form region.

Form Region Manifest Elements

Visual Studio Tools for the Office system (3.0) handles all of the details related to creating and managing a form region manifest. A form region manifest specifies attributes such as the name of the add-in that is associated with the form region, the type of form region, and its name and title. The manifest is a set of properties associated with a FormRegionControl. To modify manifest attributes, view the designer that is associated with a FormRegionControl and then modify the desired properties underneath the Manifest property in the Properties window.

Types of Form Regions

One of the elements under the Manifest property is the FormRegionType element. After you add a form region to your Visual Studio Tools for the Office system (3.0) project, you select the type of form region to add. If you change your mind later, you can change the type of form region by changing the FormRegionType property. There are four types of form regions:

  • Adjoining. Adjoining form regions display in addition to a standard or custom form. They appear in a special region at the bottom of the Inspector window or Reading Pane.

  • Replacement. Replacement form regions replace the default form of an item with the replacement form region. You can only use replacement and replace-all form regions with custom message classes.

  • Replace-all. Similar to the replacement form region, except that a replace-all form region deletes all the form pages and displays only the replace-all form region along with other form regions registered with the item's message class.

  • Separate. Separate form regions are similar to adjoining form regions in that they enhance existing forms. However, unlike adjoining form regions, separate form regions appear as an additional form page. To display a separate form region, click a button in the Show group on the Microsoft Office Fluent Ribbon.

See It Splash screen of video

Watch the Video

Video Length: 00:15:28

File Size: 32.0 MB WMV

Explore It