Add button to Outlook 2010 in C#

≡放荡痞女 提交于 2019-12-24 07:03:42

问题


I need to add some UI functionality to Outlook 2010 via C#.

I already know how to add a simple button, like Unread/Read using Ribbon XML. Now, what I need is to add a button like "Categorize" which has a small menu with several options.

When the user clicks one of the options, I want to open a corresponding form to fill out.

Two questions:

  1. How do I add this more advanced button? Is there any internet resource that explains this stuff? (So far, I could find only a walk-through for a simple button, which works fine, but I need more).

  2. The options shown when I click on this button may be different depending on some internal logic (i.e. I may want to disable one of them or not show it at all). How is this done?

  3. For the forms that are opened, is it easier to use WinForms or WPF, given that I am not familiar with either library, but know how to program in general?

Thanks!


回答1:


You can follow these steps:

  1. Create an Outlook Add-in Project
  2. Add New ItemRibbon (XML) and name it Ribbon1
  3. Paste this content to XML file:

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
        <ribbon>
            <tabs>
                <tab idMso="TabAddIns">
                    <group id="group1" label="group1">
                        <splitButton id="splitButton1" size="large">
                            <button id="splitButton1__btn" label="splitButton1"
                                    getImage="Image1" />
                            <menu id="splitButton1__mnu">
                                <button id="button1" label="button1" getImage="Image2" />
                                <button id="button2" label="button2" getImage="Image2" />
                            </menu>
                        </splitButton>
                    </group>
                </tab>
            </tabs>
        </ribbon>
    </customUI>
    
  4. In Solution Explorer → Properties → Open Resources.resx and add some images, for example:

    • Image1
    • Image2
  5. Open Ribbon1.cs and add these properties to the class:

    public System.Drawing.Bitmap Image1(IRibbonControl control)
    {
        return Properties.Resources.Image1;
    }
    public System.Drawing.Bitmap Image2(IRibbonControl control)
    {
        return Properties.Resources.Image2;
    }
    
  6. Open ThisAddin and add this method to the class:

    protected override Microsoft.Office.Core.IRibbonExtensibility 
        CreateRibbonExtensibilityObject()
    {
        return new Ribbon1();
    }
    

When you run the application an ADD-INS tab you can see your ribbon:

Note

  • If you have to add new forms to show you can simply add new Windows Form to the project.
  • You can add Ribbon (Visual Designer) too. Then You can convert it to XML by right click on ribbon and choosing Export Ribbon to XML.
  • You can find more resources in Ribbon Overview like:
    • How to: Export a Ribbon from the Ribbon Designer to Ribbon XML
    • Walkthrough: Updating the Controls on a Ribbon at Run Time.
    • Walkthrough: Creating a Custom Tab by Using Ribbon XML


来源:https://stackoverflow.com/questions/40405772/add-button-to-outlook-2010-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!