Export (0) Print
Expand All

Accessing a Form Region at Run Time

Applies to

The information in this topic applies only to the following project types and versions of Microsoft Office. For more information, see Features Available by Office Application and Project Type.

Project type

  • Application-level projects

Microsoft Office version

  • Outlook 2010

Use the Globals class to access form regions from anywhere within your Outlook project. For more information about the Globals class, see Global Access to Objects in Office Projects.

Applies to: The information in this topic applies to application-level projects for Outlook 2013 and Outlook 2010. For more information, see Features Available by Office Application and Project Type.

To access all form regions that appear in a specific Outlook Inspector, call the FormRegions property of the Globals class and pass in an Inspector object that represents the Inspector.

The following example gets the collection of form regions that appear in the Inspector that currently has focus. This example then accesses a form region in the collection named formRegion1 and sets the text that appears in a text box to Hello World.

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

To access all form regions that appear in a specific Outlook Explorer, call the FormRegions property of the Globals class and pass in an Explorer object that represents the Explorer.

The following example gets the collection of form regions that appear in the Explorer that currently has focus. This example then accesses a form region in the collection named formRegion1 and sets the text that appears in a text box to Hello World.

private void Access_Form_Regions_ByExplorer()
{
    WindowFormRegionCollection formRegions =
        Globals.FormRegions
            [Globals.ThisAddIn.Application.ActiveExplorer()];
    formRegions.FormRegion1.textBox1.Text = "Hello World";
}

To access all form regions that appear in all Explorers and all Inspectors, call the FormRegions property of the Globals class.

The following example gets the collection of form regions that appear in all Explorers and all Inspectors. This example then accesses a form region named formRegion1 and sets the text that appears in a text box to Hello World.

internal void Access_All_Form_Regions()
{
    foreach (Microsoft.Office.Tools.Outlook.IFormRegion formRegion 
        in Globals.FormRegions)
    {
        if (formRegion is FormRegion1)
        {
            FormRegion1 formRegion1 = (FormRegion1)formRegion;
            formRegion1.textBox1.Text = "Hello World";
        }
    }

}

To access controls on a form region by using the Globals class, you must make the controls accessible to code outside of the form region code file.

For C#, change the modifier of each control that you want to access. To do this, select each control in the form region designer and change the Modifiers property to Internal or public in the Properties window. For example, if you change the Modifier property of textBox1 to Internal, you can access textBox1 by typing Globals.FormRegions.FormRegion1.textBox1.

For Visual Basic, you do not need to change the modifier.

When you import a form region that was designed in Outlook, the access modifier of each control on the form region becomes private. Because you cannot use the form region designer to modify an imported form region, there is no way to change the modifier of a control in the Properties window.

To enable access to a control from outside the form region code file, create a property in the form region code file to return that control.

For more information about how to create properties in C#, see How to: Declare and Use Read/Write Properties (C# Programming Guide).

For more information about how to create properties in Visual Basic, see How to: Add Fields and Properties to a Class.

Show:
© 2014 Microsoft