How to: Prevent Outlook from Displaying a Form Region
Applies to |
---|
The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office. Project type
Microsoft Office version
For more information, see Features Available by Application and Project Type. |
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.
To prevent Outlook from displaying a form region
Open the code file for the form region you want to modify.
Expand the Form Region Factory code region.
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.
Example
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
Return
End If
End If
e.Cancel = True
End Sub
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))
{
return;
}
}
e.Cancel = true;
}
See Also
Tasks
Walkthrough: Designing an Outlook Form Region
How to: Access the Outlook Item that Displays the Form Region
How to: Add a Form Region to an Outlook Add-in Project
Walkthrough: Designing an Outlook Form Region
Walkthrough: Importing a Form Region That Is Designed in Outlook