English 中文(简体)
C#中的Outlook Addin - 如何在新邮件中添加按钮/组(位于签名旁边)
原标题:Outlook Addin in C# - How to add button/group in New Mail (next to signatures)

我有点难以理解Outlook术语(CommandBarPopup、CommandBarButton等),就像Outlook中的这些是什么一样,请耐心解释。

我想要创造一些东西:

  1. 我愿在《里布博》的签署/附文之后,在新的邮件上设立新的小组(或只是纽芬兰,但我读到不可能给一个现有集团增加一个顿)。 在你敦促它展示两种选择时,它也必须以同样的方式开展工作。 怎样才能创建?

  2. 我想覆盖一个按钮“NEW”(您可以选择发送新邮件,安排约会或执行其他操作),以便当您在主窗口中按下新按钮旁边的向下箭头时,您可以选择我将添加的选项之一?这可能吗?我该怎么做?

  3. 我有一些代码,在主窗口中添加菜单。

    private void AddMenuBar() {
        try {
            //Define the existent Menu Bar
            menuBar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar;
            //Define the new Menu Bar into the old menu bar
            newMenuBar = (Office.CommandBarPopup) menuBar.Controls.Add(Office.MsoControlType.msoControlPopup, missing, missing, missing, false);
            //If I dont find the newMenuBar, I add it
            if (newMenuBar != null) {
                newMenuBar.Caption = "Test";
                newMenuBar.Tag = menuTag;
                buttonOne = (Office.CommandBarButton) newMenuBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, 1, true);
                buttonOne.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
                buttonOne.Caption = "Test Button";
                //This is the Icon near the Text
                buttonOne.FaceId = 610;
                buttonOne.Tag = "c123";
                //Insert Here the Button1.Click event    
                buttonOne.Click += new Office._CommandBarButtonEvents_ClickEventHandler(ButtonOneClick);
                newMenuBar.Visible = true;
            }
        } catch (Exception ex) {
            //This MessageBox is visible if there is an error
            System.Windows.Forms.MessageBox.Show("Error: " + ex.Message.ToString(), "Error Message Box", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
    }
    

我想在buttonOne下面添加子菜单,这样当我按下它时,新的子菜单就会打开。我该如何实现?

最佳回答
  1. Is not possible in that the OOM does not expose this type of button :( even though MS use it. You can though hide a Button group and then create your own "similar" group by adding standard Commands, kinda giving you the same thing.

编辑:使用可见属性和其 idMso,隐藏标准操作组的 XML

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="Ribbon_Load" loadImage="GetImage">
  <ribbon>
    <tabs>
      <tab idMso="TabReadMessage">
        <group idMso="GroupActions" visible="false">   
        </group>

        <group id="newactionsgroup" label="Actions" insertAfterMso="GroupActions">
          <button idMso="Delete" size="large"/>
          <button id="MoveToFolder" imageMso="MoveToFolder" size="large" label="Move To Folder" onAction="myMoveToFolder" />
          <button idMso="CreateMailRule" size="large"/>
          <menu idMso="OtherActionsMenu" size="large"/>
        </group>
     </tab>
    </tabs>
  </ribbon>
</customUI>
  1. Not possible at all though you can again hide the existing button and create something similar with a well position form !

3. 将您的 buttonOne 创建为 CommandBarPopup。

问题回答

我不知道这是否是您在第二点中寻找的内容,但我使用以下代码成功将自定义菜单项添加到“新建”按钮下拉菜单中:

  private void AddButtonToNewDropdown()
    {
        Office.CommandBar commandBar = this.Application.ActiveExplorer().CommandBars["Standard"];
        Office.CommandBarControl ctl = commandBar.Controls["&New"];
        if (ctl is Office.CommandBarPopup)
        {
            Office.CommandBarPopup newpopup = (Office.CommandBarPopup)ctl;
            commandBarButton = (Office.CommandBarButton)newpopup.Controls.Add(1, missing, missing, missing, true);
            commandBarButton.Caption = "My custom button";
            commandBarButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(ButtonClick);
        }

    }




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签