There is no way to show or hide an adjoining form region at run time. However, you can show and hide a custom task pane at run time. Therefore, if you need to give your users the ability to show and hide a UI panel in an Outlook item, consider using a custom task pane.
The following screen shot shows a custom task pane beneath an adjoining form region. They look very similar at first glance. However, there are a few differences in their behavior and in the way they are implemented – more on that in a moment.
Implementing a Custom Task Pane that Simulates an Adjoining Form Region
To make this work, you need to create a new instance of a custom task pane when each Inspector window opens. To do this, handle an event that is raised when the Inspector window is created, and then create the task pane in the event handler.
You should always create a user interface (UI) element, such as a button, that users can click to display or hide your custom task pane, because Microsoft Office applications do not provide a default way for users to show or hide custom task panes.
For a step-by-step walkthrough that shows you how to show and hide a custom task pane in an Outlook Inspector window by using a button on the Ribbon, see the following topic: Walkthrough: Displaying Custom Task Panes with E-Mail Messages in Outlook.
Adjoining form regions appear at the bottom of an Inspector window. Therefore, to make the custom task pane appear in the same position as an adjoining form region would appear, set the DockPosition property of the CustomTaskPane to msoCTPDockPositionBottom. The following code example shows this:
taskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionBottom;
You should only use a custom task pane in this way if you need to show and hide a panel of information in an Outlook Inspector at run time. If you do not have this requirement, it is much easier to use an adjoining form region.
The following table describes some of the differences between implementing an adjoining form region and using a custom task pane to simulate an adjoining form region:
|Task||Custom Task Pane||Outlook Form Region|
|Adding native outlook controls||Not supported.||Supported.|
|Showing the UI for Inspectors that are in various display modes (for example: compose mode).||Requires custom code.||Does not require custom code.|
|Displaying the UI for different types of items (for example: Mail or Task.)||Requires custom code.||Does not require custom code.|
|Creating the UI when an Inspector opens and disposing the UI when the inspector closes.||Requires custom code.||Does not require custom code. This happens automatically.|
|Prevent the UI from appearing for derived message classes.||Requires custom code.||Does not require custom code. For more information, see Guidelines for Creating Outlook Form Regions.|
|Display the UI for all the pages of an Outlook item.||Does not require custom code. This happens automatically.||Not supported. Form regions only appear beneath the default page of an Outlook form.|
- To read more about custom task panes, see Custom Task Panes Overview.
- For more information about how to create a form region, see How to: Add a Form Region to an Outlook Add-in Project.
- To learn about the different ways you can customize the UI of a Microsoft Office application, see Office UI Customization Overview.