Technically Blogging

Monday, January 16, 2006

Adding new Page to Outlook Options Dialog (C#)

Standard way is create a new user control (a class derived from System.Windows.UserControl) and use it as your custom page.

To hook this custom page in Outlook options dialog, create an event handler for
OptionsPagesAdd event of a Application object like this:


this.OptionsPagesAdd += delegate(Outlook.PropertyPages pages)
{
pages.Add(new CustomPageControl(), "My Page");
};

Now one caveat, if you go this way-- you will encounter "operation failed" exception -- quite nasty.

Why?
Because Outlook property pages expects a control as COM activeX. By default your user control is not visible to COM, so it can't be used as property page.

Solution is to apply ComVisible(true) attribute to you custom control class like this:

[ComVisible(true)]
public class CustomPageControl:System.Windows.Forms.UserControl
{

}

Without [ComVisible(true)], you will always get operation failed exception.

0 Comments:

Post a Comment

<< Home