Link to home
Start Free TrialLog in
Avatar of Chris_Rennie
Chris_RennieFlag for United States of America

asked on

Can't display custom property page in Outlook 2007

I've followed a tutorial within a book that was written for Visual Studio 2005. Given the tutorial I can't get the new proprty page to open up in Outlook's Tools > Options page. What is wrong with the sample code?
//ThisAddIn.cs
using System;
using System.Windows.Forms;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Outlook = Microsoft.Office.Interop.Outlook;

namespace TestPropertyPage
{
    public partial class ThisAddIn
    {
        private void ThisAddIn_Startup(object sender, EventArgs e)
        {
            //Create the Options Page
            System.Windows.Forms.Application.EnableVisualStyles();
            Application.OptionsPagesAdd += new Outlook.ApplicationEvents_11_OptionsPagesAddEventHandler(ThisAddIn_OptionsPagesAdd);
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        private void ThisAddIn_OptionsPagesAdd(Outlook.PropertyPages pages)
        {
            pages.Add(new OptionPage(), "");
        }
        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
        
        #endregion
    }
}


//OptionPage.cs
using System;
using System.Windows.Forms;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Runtime.InteropServices;

namespace TestPropertyPage
{
    public partial class OptionPage : UserControl, Outlook.PropertyPage
    {
        const int captionDispID = -518;
        bool isDirty = false;
        
        public OptionPage()
        {
            InitializeComponent();
        }

        void Outlook.PropertyPage.Apply()
        {
            MessageBox.Show("The user clicked the apply button.");
        }

        bool Outlook.PropertyPage.Dirty
        {
            get
            {
                return isDirty;
            }
        }

        void Outlook.PropertyPage.GetPageInfo(ref string helpFile, ref int helpContext)
        {
        }

        [DispId(captionDispID)]
        public string PageCaption
        {
            get
            {
                return "Test Property Page";
            }
        }
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Chris_Rennie
Chris_Rennie
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial