Common Properties on Outlook Controls

If you’ve started to take advantage of the new Outlook controls on form regions in Outlook 2007, you may have noticed something strange. None of the controls have common properties you would expect all controls to have: Visible, Width, Height, Top, Left, etc. You might be thinking we missed some obvious test case here, but you’d be wrong.

These properties do in fact exist on the controls. However, because of a complexity of COM and Office dependencies, the properties do not show up in the type library exposed by Outlook.

Each of the Outlook controls (they all start with Olk in the type library) also implement the Control interface from fm20.dll. This interface includes all common properties, including Height, Width, Top, Left, Name, Parent, TabIndex, TabStop, Visible and more.

If you are using a language that supports late binding for COM objects, you can just reference the property directly and everything will work as expected.

If you’re writing managed code, or other code which requires explicit definitions of the properties, you will need to cast the control object to the Control interface from fm20.dll to read or write these properties. For example, if you’re writing in C#, you would need to do something like the following:

using Outlook = Microsoft.Office.Interop.Outlook;
using MSForms = Microsoft.Vbe.Interop.Forms;

public void BeforeFormRegionShow(Outlook.FormRegion FormRegion)
    // Find OlkButton1 and make it invisible
    MSForms.UserForm canvas = FormRegion.Form as MSForms.UserForm;
    Outlook.OlkCommandButton button1 =
        canvas.Controls.Item("OlkButton1") as Outlook.OlkCommandButton;
    //button1.Visible = false; // can't do this, it doesn't compile
    MSForms.Control ctrlButton1 = (MSForms.Control)button1;
    ctrlButton1.Visible = false; // this works!

We tried to find a way to combine these two interfaces together, but because Outlook doesn’t have a dependency on the Microsoft Forms library, it wasn’t feasible to make it work right. There is at least a work-around for developers who need to access these properties.

You can also access additional Outlook-specific properties on controls by casting the control to the OlkControl interface in Outlook. This interface provides you with the ability to control layout settings for how the control will behave on the form. These properties can be set either at runtime or design time, as long as you set them before the layout is calculated (which occurs just after BeforeFormRegionShow).