问题
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:
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).
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?
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:
- Create an Outlook Add-in Project
- Add New Item → Ribbon (XML) and name it
Ribbon1
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>
In Solution Explorer → Properties → Open
Resources.resx
and add some images, for example:- Image1
- Image2
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; }
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