Displaying Multiple Task Panes

You can add multiple Custom task panes to an application. As shown in Figure 14.37, each task pane is opened next to the last one added (tiled). You'll use the code from our Styles and Formatting task pane example.

1. Add a new user control to the project.

2. Add a button to the user control.

3. Append the code in Listing 14.32 to the Startup event handler of ThisAddin, and press F5.

Figure 14.37. Adding two custom task panes

Listing 14.32. Adding another task pane

Dim newControl As New UserControl2 Me.CustomTaskPanes.Add(NewControl, _

"Another task pane").Visible = True

You might also want to control the number of task panes that can be visible at one time. Because the Custom task panes tile, theoretically you could add enough task panes to take up the application's entire screen real estate. To avoid this problem, you could first check whether other Custom task panes in the collection are visible before you make your Custom task pane visible. Remember that users may have any number of add-ins loaded that might display a Custom task pane.

Outlook handles Custom task panes a little differently than other Office applications. As an internal optimization, Outlook might reuse a Custom task pane that was associated with an Inspector previously. This could lead to having multiple Custom task panes for the same Inspector. The best practice for avoiding this is to explicitly delete all Custom task panes you add by using the Remove method of the CustomTaskPaneCollection when the Inspector is closed.

0 0

Post a comment