How to: Prevent Outlook from displaying a form region

Applies to: yesVisual Studio noVisual Studio for Mac


This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

There might be situations in which you do not want Microsoft Office Outlook to display a form region for a particular item. For example, if a contact item does not contain a business address, you can prevent a form region that shows the location of the business in a map from appearing.

Applies to: The information in this topic applies to VSTO Add-in projects for Outlook. For more information, see Features available by Office application and project type.

To prevent Outlook from displaying a form region

  1. Open the code file for the form region you want to modify.

  2. Expand the Form Region Factory code region.

  3. Add code to the FormRegionInitializing event handler that sets the Cancel property of the FormRegionInitializingEventArgs class to true.

    In this example, if the contact item does not contain an address, the Cancel property is set to true, and the form region does not appear.


private void MapItFactory_FormRegionInitializing(object sender,
    Microsoft.Office.Tools.Outlook.FormRegionInitializingEventArgs e)
    Outlook.ContactItem myItem = (Outlook.ContactItem)e.OutlookItem;

    if (myItem != null)
        if ((myItem.BusinessAddress != null &&
                myItem.BusinessAddress.Trim().Length > 0) ||
            (myItem.HomeAddress != null && 
                myItem.HomeAddress.Trim().Length > 0) ||
            (myItem.OtherAddress != null && 
                myItem.OtherAddress.Trim().Length > 0))

    e.Cancel = true;
Private Sub MapItFactory_FormRegionInitializing(ByVal sender As Object, ByVal e As Microsoft.Office.Tools.Outlook.FormRegionInitializingEventArgs) Handles Me.FormRegionInitializing

    Dim myItem As Outlook.ContactItem = CType(e.OutlookItem, Outlook.ContactItem)

    If Not (myItem Is Nothing) Then
        If Not (myItem.BusinessAddress Is Nothing) AndAlso myItem.BusinessAddress.Trim().Length > 0 Or (Not (myItem.HomeAddress Is Nothing) AndAlso myItem.HomeAddress.Trim().Length > 0) Or (Not (myItem.OtherAddress Is Nothing) AndAlso myItem.OtherAddress.Trim().Length > 0) Then
        End If
    End If

    e.Cancel = True

End Sub

See also