Home > Articles > Programming > Visual Studio

This chapter is from the book

Outlook Form Region Programmability

In this section, we examine in more detail the Outlook form region classes that VSTO creates. As with many other VSTO project items, it uses partial classes to display user code (code edited by the developer of the add-in) and associate it with generated code (code generated by Visual Studio) to build the final Outlook form region class.

The VSTO Form Region Class

In the example from the first section of this chapter, right-clicking Form-Region1.cs and choosing View Code from the context menu shows the user code:

partial class FormRegion1

You can also see the generated code by expanding FormRegion1.cs and double-clicking the file FormRegion1.Designer.cs, which is a child of FormRegion1.cs. Here, you see this line of code, showing that a VSTO form region class derives from Microsoft.Office.Tools.Outlook.FormRegionControl:

partial class FormRegion1 :

Then, if you look at the definition of FormRegionControl, you see that it derives from System.Windows.Forms.UserControl. A form region class is primarily a Windows Forms UserControl with extensions like the implementation of the IFormRegion interface, which is used by VSTO to start and shut down a form region:

public class FormRegionControl : UserControl, IFormRegion

When you import an .OFS file, the form region class derives from Microsoft.Office.Tools.Outlook.ImportedFormRegion.

The Form Region Factory

The form region factory is mostly an internal implementation detail of how VSTO supports Outlook form regions. You can do some advanced things with custom form region factories, such as having your form region classes in a separate assembly from the add-in or having a single factory to handle multiple form region classes. But outside these advanced scenarios, the form region factory does peek through in one significant way: It exposes the FormRegionInitializing method, which can be handled in your code to prevent a form region from being displayed for a particular Outlook item based on criteria you set. As you might expect, the Factory object creates an instance of your form region class every time an Outlook item requires a form region to be displayed. If you have an Adjacent form region that displays in the reading pane for a list of mail items, for example, each time the selection changes to a different mail item, a new instance of your form region class is created for the current mail item. The factory object is invoked first, and if the FormRegionInitializing method doesn’t cancel the creation of the form region by the implementation of the method setting the Cancel property of the e parameter to true, a new instance of the form region class is created.

When you import an .OFS file, the form region factory also has a method called InitializeManifest in which you can write code to modify settings for the form region, such as the form region type. With Windows Forms-based form regions, you typically modify these form region settings in the Properties window, and no Initial-izeManifest method is in the form region factory.

Another key element of the form region factory class is the Form-RegionMessageClass attribute, which sets the message classes—both built-in and custom—the form region will be displayed for. Listing 16-6 shows the attributes of a form region factory class associated with three built-in message classes (Appointment, Contact, and Note) and one custom message class that derives from Task (IPM.Task.Foo). VSTO provides constant strings in the Microsoft.Office.Tools.Outlook.FormRegionMessageClassAttribute namespace for each of the built-in Outlook message classes. If you want, you can interchange the constant string. The string "IPM.Task", for example, is equivalent to the Microsoft.Office.Tools.Outlook.FormRegionMessageClassAttribute.Task constant.

Listing 16-6. A Form Region Factory Class Associated with Three Built-In Message Classes and One Custom Message Class via FormRegionMessageClass Attributes

public partial class FormRegion3Factory

The Manifest Object

Most of the properties that control how a VSTO form region is displayed by Outlook are found in the FormRegionManifest object returned by the Manifest property of a VSTO form region. Behind the scenes, setting properties on the FormRegionManifest object manipulates an XML manifest that describes the form region. This manifest is provided to Outlook when the add-in loads. You can modify the properties of the FormRegionManifest object via the property grid for Windows Forms-based form regions by clicking the form region surface in the designer and then using the Properties window to set properties associated with the Manifest property, as shown in Figure 16-30.

Figure 16-30

Figure 16-30 Setting properties on the manifest object for a Windows Forms-based form region.

To set properties of the manifest object for a Outlook Forms-based form region, write code in the InitializeManifest method of the form region factory. If you try to set properties on the manifest object outside these two mechanisms (the Properties window for Windows Forms and the InitializeManifest method for Outlook Forms), chances are that Outlook will already have asked for the manifest object’s settings, and your code will generate an InvalidOperationException. You can use the Locked property of the manifest object to check whether Outlook has already retrieved the settings from the manifest object. If Locked is set to true, any code you write against the manifest object will have no effect.

Table 16-4 describes the various properties of the manifest object. The table refers several times to the Choose Form dialog box, which you invoke by dropping down the New button in the Explorer window and choosing Choose Form, as shown in Figure 16-31. The dialog box shown in Figure 16-32 appears, allowing you to pick Replacement or Replace-All form regions (which are associated with custom message classes). This way, an end user can create an Outlook item with a custom message class that you defined and associated with a form region. Table 16-5 describes the icons that can be used by a form region.

Table 16-4. Properties of the Manifest Object



What It Does



Gets and sets the name used in the Choose Form dialog box for Replacement and Replace-All form regions.



A collection with custom actions associated with the form region. The custom actions appear in a Custom Actions group in the Ribbon of the Inspector window showing the form region.



Gets and sets the description used in the Choose Form dialog box for Replacement and Replace-All form regions.



Gets or sets the name of the form region to display before this form region.



If set to true, this property prevents a custom message class derived from the message class for the form region from displaying the form region.



Gets and sets the name used for the Ribbon button associated with this form region or the header associated with an Adjoining form region.



Gets and sets an enum specifying the form region type: Adjoining, Replacement, Replace-All, or Separate.



If set to true, this form region won’t be displayed in the Choose Form dialog box.



Sets the icons used by the form region (see Table 16-5).



Returns true if Outlook has already queried the manifest object for its settings. Any code you write against the manifest object after Locked is set to true has no effect.



Gets and sets the keyboard shortcuts for Separate, Replacement, and Replace-All form regions.



Gets and sets whether the form region is shown when an Inspector window is in compose mode.



Gets and sets whether the form region is shown when an Inspector window is in read mode.



Gets and sets whether a form region is shown for the reading pane.



Gets and sets the name that appears in the Actions menu and the Choose Form dialog box for Replacement and Replace-All form regions.

Figure 16-31

Figure 16-31 Creating a new Outlook Item by using the Choose Form button.

Figure 16-32

Figure 16-32 The Choose Form dialog box.

Table 16-5. Icons on the Manifest Object


What It Does

Applies to Form Region Types


16 × 16-pixel icon that is used by default.

Replacement and Replace-All


16 × 16-pixel icon for encrypted items.

Replacement and Replace-All


16 × 16-pixel icon for forwarded items.

Replacement and Replace-All


Icon used in the Ribbon of an Inspector window for the button that activates the form region. Use a PNG file for this icon.

Separate, Replacement, and Replace-All


16 × 16-pixel icon for read items.

Replacement and Replace-All


16 × 16-pixel icon for recurring items.

Replacement and Replace-All


16 × 16-pixel icon for replied-to items.

Replacement and Replace-All


16 × 16-pixel icon for digitally signed items.

Replacement and Replace-All


16 × 16-pixel icon for items in the Outbox that are submitted for sending.

Replacement and Replace-All


16 × 16-pixel icon for unread items.

Replacement and Replace-All


16 × 16-pixel icon for items in the Drafts folder that are not yet sent.

Replacement and Replace-All


Appears in the notification area and in the Alt+Tab window for Inspector windows displaying the form region. Use a 32 × 32-pixel icon.

Replacement and Replace-All

Other Key Properties and Methods

Several other properties and methods associated with a Outlook form region class created with VSTO are worth pointing out. We’ve already talked about the OutlookItem property, which returns as an object the Outlook Item associated with the Outlook form region. You can cast the object returned by the OutlookItem property to the type of Outlook item you expect, based on what built-in or custom message classes your form region is associated with.

The OutlookFormRegion property returns the underlying Microsoft.Office.Interop.Outlook.FormRegion object, which represents your form region in the Outlook object model. Table 16-6 shows some of the key properties and methods on this object.

Table 16-6. Key Properties and Methods on the FormRegion Object Returned by the OutlookFormRegion Property



What It Does



Gets and sets the name displayed in the header after the display name of an Adjoining form region.



Returns the Inspector window object associated with the form region.



Read-only property that returns true when an Adjoining form region is expanded.



Returns the locale ID (LCID) for the current language used by Outlook.


Method that forces Outlook to size an Adjoining form region so that all controls are visible.


Makes the form region the active form region and forces it to be visible.

Globals Support

Whenever you create a form region in a VSTO project, it is added to the Globals object for the project. You can access the currently active form regions in three ways: You can see all the active form regions for a particular Inspector window, for a particular Explorer window, or for all open windows. You can access only form regions provided by your add-in; you can’t access form regions provided by other add-ins by using the Globals object.

Listing 16-7 shows a subroutine that uses all three ways of accessing active form regions to get the count of active form regions associated with the active Explorer window, the count of active form regions associated with the active Inspector window, and the total count of all active form regions.

Listing 16-7. Three Methods of Accessing Active Form Regions: All Active, for an Explorer Window, and for an Inspector Window

private void ShowActiveFormRegions()
  Outlook.Explorer explorer =
  Outlook.Inspector inspector =

    String.Format("{0} total form regions",

  if (explorer != null)
      String.Format("{0} for regions for the active Explorer",

  if (inspector != null)
      String.Format("{0} for regions for the active Inspector",

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020