none
Customize Outlook "options" dialog RRS feed

  • Question

  • How do I customize Outlook options dialog (file -> options), adding a new panel? It is possible?

    I want to put my addin configurations like in this picture:

     


    The way of C#
    Wednesday, October 19, 2011 7:18 PM

Answers

  • Hi Marcelo,

    Adding a new option in the place where you show us in your illustration is not possible as far as I know. Just like Ken has told you that you can use Application.OptionPagesAdd event to add a new custom property page to Options dialog. However, this option dialog is placed where you can see in the following illustration:

    If you are interesting on how to implement this, please follow the steps below:

    1. Create a Outlook 2010 add-in
    2. Add a new UserControl item to the project 
    3. Drag and drop some controls into the usercontrol and basically, you need to modify the code behind the usercontrol to make it as a custom property page, check the code below:
    4. using System.Runtime.InteropServices;
      using Outlook = Microsoft.Office.Interop.Outlook;
      
      namespace OATest
      {
          [ComVisible (true)]
          public partial class UserControl1 : UserControl, Outlook.PropertyPage
          {
              const int captionDispID = -518;
              bool isDirty = false;
              public UserControl1()
              {
                  InitializeComponent();           
              }
              void Outlook.PropertyPage.Apply()
              {
      
              }
              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 page";
                  }
              }
          }
      }
      
    5. Now you can handle the event which I mentioned above to add  the custom property page:
    6.         private void ThisAddIn_Startup(object sender, System.EventArgs e)
              {
                  Outlook.Application oOutlook = Globals.ThisAddIn.Application;
                  oOutlook.OptionsPagesAdd += new Outlook.ApplicationEvents_11_OptionsPagesAddEventHandler(Application_OptionsPagesAdd);            
              }
              void Application_OptionsPagesAdd(Outlook.PropertyPages Pages)
              {
                  Pages.Add(new UserControl1(), "");
              }
      
    7. Built the project and launch Outlook again, navigate to File -> Options -> Add-Ins -> click Add-in Options button, the user control will be displayed.
    I hope this can help you.
    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Thursday, October 20, 2011 6:52 AM
    Moderator

All replies


  • --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Marcelo de Aguiar" <=?utf-8?B?TWFyY2VsbyBkZSBBZ3VpYXI=?=> wrote in message news:f7dd6f82-13e7-4a28-8316-9c535eaa7518...

    How do I customize Outlook options dialog (file -> options), adding a new panel? It is possible?

    I want to put my addin configurations like in this picture:

     


    The way of C#

    Ken Slovak MVP - Outlook
    Wednesday, October 19, 2011 7:23 PM
  • I knew about backstage view, but this is not where I think options.

    My question is: is possible to customize the options dialog?

     

    Obs: sorry by the double post.


    The way of C#
    Wednesday, October 19, 2011 7:36 PM
  • For that you need to supply a user control as the page in the Application.OptionPagesAdd() event.
     
    You can look at the sample addin templates on my Web site and see some examples of creating a Tools, Options type property page for Outlook 2007. That would be what you're looking for in Outlook 2010. The templates are at
    http://www.slovaktech.com/outlook_2007_templates.htm
    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Marcelo de Aguiar" <=?utf-8?B?TWFyY2VsbyBkZSBBZ3VpYXI=?=> wrote in message news:52715e81-6087-4d02-9f34-733a4ea20b4c...

    I knew about backstage view, but this is not where I think options.

    My question is: is possible to customize the options dialog?

     

    Obs: sorry by the double post.


    The way of C#

    Ken Slovak MVP - Outlook
    Wednesday, October 19, 2011 8:50 PM
  • Hi Marcelo,

    Adding a new option in the place where you show us in your illustration is not possible as far as I know. Just like Ken has told you that you can use Application.OptionPagesAdd event to add a new custom property page to Options dialog. However, this option dialog is placed where you can see in the following illustration:

    If you are interesting on how to implement this, please follow the steps below:

    1. Create a Outlook 2010 add-in
    2. Add a new UserControl item to the project 
    3. Drag and drop some controls into the usercontrol and basically, you need to modify the code behind the usercontrol to make it as a custom property page, check the code below:
    4. using System.Runtime.InteropServices;
      using Outlook = Microsoft.Office.Interop.Outlook;
      
      namespace OATest
      {
          [ComVisible (true)]
          public partial class UserControl1 : UserControl, Outlook.PropertyPage
          {
              const int captionDispID = -518;
              bool isDirty = false;
              public UserControl1()
              {
                  InitializeComponent();           
              }
              void Outlook.PropertyPage.Apply()
              {
      
              }
              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 page";
                  }
              }
          }
      }
      
    5. Now you can handle the event which I mentioned above to add  the custom property page:
    6.         private void ThisAddIn_Startup(object sender, System.EventArgs e)
              {
                  Outlook.Application oOutlook = Globals.ThisAddIn.Application;
                  oOutlook.OptionsPagesAdd += new Outlook.ApplicationEvents_11_OptionsPagesAddEventHandler(Application_OptionsPagesAdd);            
              }
              void Application_OptionsPagesAdd(Outlook.PropertyPages Pages)
              {
                  Pages.Add(new UserControl1(), "");
              }
      
    7. Built the project and launch Outlook again, navigate to File -> Options -> Add-Ins -> click Add-in Options button, the user control will be displayed.
    I hope this can help you.
    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Thursday, October 20, 2011 6:52 AM
    Moderator
  • This is an awesome answer!

     

    Tks.


    The way of C#
    Thursday, October 20, 2011 11:49 AM
  • How can I notify the UI of an update to the Dirty property?

    According to this walkthrough, you need to call OnStatusChange

    And according to this page, OnStatusChange is exposed by calling the Parent property to get the PropertyPageSite

    However, whenever I call it, Parent return null, so I don't have a way of updating the UI and enabling the Apply Button.

    Tuesday, January 14, 2014 9:32 PM
  • You have to use a hack to get everything working.

    In the PropertyPageLoad() event handler for your property page user control you need code something like this C# code:

    // at class level:
           private Outlook.PropertyPageSite _site = null;

            private void PropertyPage_Load(object sender, EventArgs e)
            {
                try
                {
                    // Hack: uses reflection to call a private unsafe method to get the property page site object
                    Type userControlType = typeof(System.Object);
                    string assembly = userControlType.Assembly.CodeBase.Replace("mscorlib.dll", "System.Windows.Forms.dll");
                    assembly = assembly.Replace("file:///", "");
                    string assemblyName = System.Reflection.AssemblyName.GetAssemblyName(assembly).FullName;

                    Type unsafeMethods = Type.GetType(System.Reflection.Assembly.CreateQualifiedName(assemblyName, "System.Windows.Forms.UnsafeNativeMethods"));

                    Type oleObjectType = unsafeMethods.GetNestedType("IOleObject");
                    System.Reflection.MethodInfo method = oleObjectType.GetMethod("GetClientSite");

                    if (method != null)
                    {
                        try
                        {
                            this._site = (Outlook.PropertyPageSite)method.Invoke(this, null);
                        }
                        catch
                        {
                            this._site = null;
                        }
                    }
                    else
                    {
                        this._site = null;
                    }

                    if (this._site != null)
                    {
                        // finish initializations
                    }
                }
                catch
                {
                    this._site = null;
                }
            }


    Ken Slovak MVP - Outlook

    Wednesday, January 15, 2014 2:50 PM
  • Calvin and Ken, this is fantastic!

    Can you or Ken point me in the direction of some code where I can use a checkbox in options to unhide or hide some options on my dropdown menu? Basically I want to hide certain options unless the user goes into options and checks a box.

    Here's an example of my drop down-

    I'm not sure where to start. The ribbon code or the ThisAddin.cs for the logic. Can I use the control hide method-

    http://msdn.microsoft.com/en-us/library/system.windows.forms.control.hide(v=vs.110).aspx

    do you think ?

     //this contains the classfication options. 
            private void classificationSplitButton_Click(object sender, RibbonControlEventArgs e)
            {
    
            }
    
    
            //this is the KeyCorp Public email classification button
            private void publicCheckBox_Click(object sender, RibbonControlEventArgs e)
            {
                var addin = Globals.ThisAddIn;
                
                if (publicCheckBox.Checked)
                {
           
                    addin.classification(1);
                    InternalCheckBox.Checked = false;
                    ConfidentialcheckBox.Checked = false;
    
                }
    
    
                if (publicCheckBox.Checked == false)
                {
                  
                    addin.cancelClassification();
    
                }
    
      
                
            }
    
    
            //this is the KeyCorp Internal email classification button
            private void InternalCheckBox_Click(object sender, RibbonControlEventArgs e)
            {
    
                var addin = Globals.ThisAddIn;
                
                if (InternalCheckBox.Checked)
                {
    
                    addin.classification(2);
                    publicCheckBox.Checked = false;
                    ConfidentialcheckBox.Checked = false;
                }
    
    
                if (InternalCheckBox.Checked == false)
                {
                   
                    addin.cancelClassification();
    
                }
    
    
            }
    
    
            //this is the KeyCorp Confidential email classification button
            private void ConfidentialcheckBox_Click(object sender, RibbonControlEventArgs e)
            {
    
                var addin = Globals.ThisAddIn;
               
                if (ConfidentialcheckBox.Checked)
                {
    
                    addin.classification(3);
                    publicCheckBox.Checked = false;
                    InternalCheckBox.Checked = false;
    
                }
    
    
    
                if (ConfidentialcheckBox.Checked == false)
                {              
    
                    addin.cancelClassification();
    
                }
    
            }

    here's the code from-  ThisAddin.cs

            //Below are the variables I am using for email classification function.
            private string PublicText = "Public";
            private string InternalText = "Internal";
            private string ConfidentialText = "Confidential";

            //This is the main method for adding classification. When any of the classification is selected, this function is called.
            public void classification(int type)
            {
                
                //calls the public classification function
                if (type == 1)
                {
                    this.Application.ItemSend -= new Outlook.ApplicationEvents_11_ItemSendEventHandler(Classification_Confidential);
                    this.Application.ItemSend -= new Outlook.ApplicationEvents_11_ItemSendEventHandler(Classification_Internal);
                    this.Application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(Classification_Public);
    
                //calls the internal classification function
                }else if(type == 2)
                {
                    this.Application.ItemSend -= new Outlook.ApplicationEvents_11_ItemSendEventHandler(Classification_Public);
                    this.Application.ItemSend -= new Outlook.ApplicationEvents_11_ItemSendEventHandler(Classification_Confidential);
                    this.Application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(Classification_Internal);
    
                //calls the confidential classification function
                }else if(type == 3)
                {
                    this.Application.ItemSend -= new Outlook.ApplicationEvents_11_ItemSendEventHandler(Classification_Internal);
                    this.Application.ItemSend -= new Outlook.ApplicationEvents_11_ItemSendEventHandler(Classification_Public);
                    this.Application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(Classification_Confidential);
    
                }
            }
    
    
            
            //the internal classification function calls this function and this adds the text on the mail body. 
            void Classification_Internal(object Item, ref bool Cancel)
            {
    
                if (Item is Outlook.MailItem)
                {
                    Outlook.MailItem mi = Item as Outlook.MailItem;
                    mi.HTMLBody += String.Concat(lineBreak, InternalText);
                }
    
                this.Application.ItemSend -= new Outlook.ApplicationEvents_11_ItemSendEventHandler(Classification_Internal);
    
            }
    
    
    
            //the public classifcation funtion calls this function and this adds the text on the mail body.
            void Classification_Public(object Item, ref bool Cancel)
            {
    
                if (Item is Outlook.MailItem)
                {
    
                    Outlook.MailItem mi = Item as Outlook.MailItem;
                    mi.HTMLBody += string.Concat(lineBreak, PublicText);
           
                }
    
                this.Application.ItemSend -= new Outlook.ApplicationEvents_11_ItemSendEventHandler(Classification_Public);
            }
    
    
    
            //the confidential classifcation funtion calls this function and this adds the text on the mail body.
            void Classification_Confidential(object Item, ref bool Cancel)
            {
    
                if (Item is Outlook.MailItem)
                {
    
                    Outlook.MailItem mi = Item as Outlook.MailItem;
                    mi.HTMLBody += string.Concat(lineBreak, ConfidentialText);
                }
    
                this.Application.ItemSend -= new Outlook.ApplicationEvents_11_ItemSendEventHandler(Classification_Confidential);
    
            }
    
    
    
    
            //This cancels all the classification functions when the all the classification button is unchecked.
            public void cancelClassification()
            {
    
                this.Application.ItemSend -= new Outlook.ApplicationEvents_11_ItemSendEventHandler(Classification_Internal);
                this.Application.ItemSend -= new Outlook.ApplicationEvents_11_ItemSendEventHandler(Classification_Public);
                this.Application.ItemSend -= new Outlook.ApplicationEvents_11_ItemSendEventHandler(Classification_Confidential);
    
            }
    
    

    Saturday, April 5, 2014 1:49 AM
  • Please do not hijack old closed threads, start one of your own.

    See http://msdn.microsoft.com/en-us/library/bb608602.aspx for information on adding controls to "Backstage", the area shown when you click File. Among the controls you can use are checkboxes.

    The other methods of customizing Options are mentioned in the thread.


    Ken Slovak MVP - Outlook

    Monday, April 7, 2014 1:52 PM