在C#中将按钮添加到Outlook 2010 [英] Add button to Outlook 2010 in C#

查看:115
本文介绍了在C#中将按钮添加到Outlook 2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过C#向Outlook 2010添加一些UI功能.

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

我已经知道如何添加一个简单的按钮,例如使用Ribbon XML进行未读/读". 现在,我需要添加一个按钮,例如"Categorize",其中有一个带有几个选项的小菜单.

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.

两个问题:

  1. 如何添加此更高级的按钮?是否有任何互联网资源可以解释这些内容? (到目前为止,我只能找到一个简单按钮的演练,它可以正常工作,但我还需要更多内容.)

  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).

当我单击此按钮时显示的选项可能会有所不同,具体取决于某些内部逻辑(即,我可能要禁用其中一个或根本不显示它).怎么做?

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?

对于打开的表单,考虑到我对这两个库都不熟悉,但知道如何编程,是否更容易使用WinForms或WPF?

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?

谢谢!

推荐答案

您可以按照以下步骤操作:

You can follow these steps:

  1. 创建一个 Outlook加载项项目
  2. 添加新项功能区(XML)并将其命名为Ribbon1
  3. 将此内容粘贴到XML文件:

  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>

  • 在解决方案资源管理器中→属性→打开Resources.resx并添加一些图像,例如:

  • In Solution Explorer → Properties → Open Resources.resx and add some images, for example:

    • 图片1
    • Image2

    打开Ribbon1.cs并将以下属性添加到类中:

    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;
    }
    

  • 打开ThisAddin并将此方法添加到类中:

  • Open ThisAddin and add this method to the class:

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

  • 在运行应用程序时,会出现一个ADD-INS标签,您可以看到功能区:

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

    注意

    • 如果必须添加新表单来显示,则只需将新Windows表单添加到项目中即可.
    • 您也可以添加 Ribbon(Visual Designer).然后,您可以通过右键单击功能区并选择将功能区导出为XML 来将其转换为XML.
    • 您可以在丝带概述中找到更多资源,例如:
      • 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

        这篇关于在C#中将按钮添加到Outlook 2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆