Do Your Outlook UI Elements Need Counseling? - Get your Form Regions, Ribbons, and Task Panes Talking to Each Other Again (Norm Estabrook)

  • Comments 1

So you want to open a task pane by using a button on the Ribbon. You also want a form region that appears in an e-mail item to detect the state of a control on a custom task pane so that you can add or remove an option that appears in a Ribbon menu right? Ok, I completely made this scenario up. But at some point, somewhere along the way, you might say to yourself – how do I get to that gallery on my Ribbon from my task pane? or how do I enable the user to populate that combo box on the form region by selecting a control on the Ribbon? Well if that describes something that you are trying to do, then this post is for you. Let’s start with Ribbons. The other two (form regions and task panes) are bit more troublesome.

Ribbons

Ribbon controls are the easiest to access from other areas of your application. Assuming that your custom Ribbon is named Ribbon1, here is what you do:

ThisRibbonCollection ribbonCollection =
    Globals.Ribbons
        [Globals.ThisAddIn.Application.ActiveInspector()];
ribbonCollection.Ribbon1.comboBox1.Text = "Hello World";

You can read more about this here.

Form Regions

For the VB folks, this is a snap. C# developers have to do a bit more work. That is because by default, in a C# project, the controls that you add to a form region are private. For each control that you want to access, you have to set the Modifiers property of the control to Internal or Public. For example:

image

You can then add code to access the control. For example, assuming that your form region is named FormRegion1, you could use the following code:

WindowFormRegionCollection formRegions =
    Globals.FormRegions
        [Globals.ThisAddIn.Application.ActiveInspector()];
formRegions.FormRegion1.textBox1.Text = "Hello World";

You can read more about this here.

Custom Task Panes

Controls on task panes require the same tweaks described for form regions above.  Here is an example of how to get to a button on a task pane. This example makes the following assumptions:

  • The user control of the custom task pane is named MyUserControl.
  • The task pane is named myCustomTaskPane and it is declared as public in your code.

((MyUserControl)Globals.ThisAddIn.myCustomTaskPane.Control).button1.Text = "It Worked";

If have not yet created a custom task pane, see this topic and it will all make sense.

As a side note, if you are adding custom task panes to Outlook Inspector windows, you have to write a bit of code to map each Inspector window with it’s own instance of a custom task pane. If you don’t do this mapping, you get all kinds of wacky issues.  For an example of how to do this, see the following article.

For the sake of being thorough, here is an example of how you can access a task pane created by using the guidance in that article

private void toggleButton1_Click(object sender, RibbonControlEventArgs e)
{
    Outlook.Inspector inspector = (Outlook.Inspector)e.Control.Context;
    InspectorWrapper inspectorWrapper = Globals.ThisAddIn.InspectorWrappers[inspector];
    CustomTaskPane taskPane = inspectorWrapper.CustomTaskPane;
    if (taskPane != null)
    {
        taskPane.Visible = ((RibbonToggleButton)sender).Checked;
        taskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionBottom;
        taskPane.Height = 475;
    }
}

Hope this helps!

Norm E.

Leave a Comment
  • Please add 8 and 4 and type the answer here:
  • Post

Do Your Outlook UI Elements Need Counseling? - Get your Form Regions, Ribbons, and Task Panes Talking to Each Other Again (Norm Estabrook)