use*_*155 1 outlook vsto add-in outlook-addin outlook-2010
我正在开发一个 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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我正在AddButtonToNewDropdown()从事件中调用方法ThisAddIn_Startup。
您需要CommandBarButton在范围内创建类成员变量 - 否则它将被垃圾收集,并且事件不会像您所观察到的那样触发。
public class ThisAddIn
{
Office.CommandBarButton commandBarButton;
private void AddButtonToNewDropdown()
{
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
请参阅有关类似问题的相关 SO 帖子。
| 归档时间: |
|
| 查看次数: |
1819 次 |
| 最近记录: |