繁体   English   中英

单击自定义按钮后,Outlook事件不会被触发

[英]Outlook Event is not getting fired on click of custom button

我正在开发一个Microsoft Outlook加载项,我在加载项选项卡名称OPENISMS中添加了一个按钮。 我可以看到按钮,但是点击该事件不会被触发。 我不知道为什么它以这种方式表现。 请在下面找到添加按钮和附加事件的代码。 任何帮助将受到高度赞赏。

private void AddButtonToNewDropdown()
{
    Office.CommandBar commandBar = this.Application.ActiveExplorer().CommandBars["Standard"];
    Office.CommandBarControl ctl = commandBar.Controls["&New"];
    if (ctl is Office.CommandBarPopup) 
    {
        Office.CommandBarButton commandBarButton;
        Office.CommandBarPopup newpopup = (Office.CommandBarPopup)ctl;
        commandBarButton = (Office.CommandBarButton)newpopup.Controls.Add(1, missing, missing, missing, true);
        commandBarButton.Caption = "OpenISMS";
        commandBarButton.Tag = "OpenISMS";
        commandBarButton.FaceId = 6000;
        //commandBarButton.Enabled = false;
                      commandBarButton.OnAction = "OpenISMSThruMail.ThisAddIn.ContextMenuItemClicked";
        commandBarButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(ContextMenuItemClicked); 
    }

}
private void ContextMenuItemClicked(CommandBarButton Ctrl, ref bool CancelDefault)
{
    if (currentExplorer.Selection.Count > 0)
    {
        object selObject = currentExplorer.Selection[1];
        if (selObject is MailItem)
        {
            // do your stuff with the selected message here
            MailItem mail = selObject as MailItem;
            MessageBox.Show("Message Subject: " + mail.Subject);
        }
    }
} 

我从ThisAddIn_Startup事件调用AddButtonToNewDropdown()方法。

您需要将CommandBarButton作为范围内的类成员变量 - 否则它将被垃圾收集,并且事件不会像您观察到的那样触发。

public class ThisAddIn
{
   Office.CommandBarButton commandBarButton;

   private void AddButtonToNewDropdown()
   {
     // ...
   }
}

查看有关类似问题的相关SO帖子

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM