【发布时间】:2011-09-19 23:28:00
【问题描述】:
我有一个在启动时加载的 VSTO Outlook 2007 插件。加载时会执行以下操作:
Private Sub ThisAddIn_Startup() Handles Me.Startup
explorer = Me.Application.ActiveExplorer()
AddHandler Application.ItemContextMenuDisplay, AddressOf Application_ItemContextMenuDisplay
AddHandler Application.Startup, AddressOf Application_CommandBarMenuDisplay
End Sub
然后,AddHandlers 执行以下操作:
Sub Application_CommandBarMenuDisplay()
Dim cBar As Office.CommandBar = explorer.CommandBars("Standard")
btnCommandBarMenu = CType(cBar.Controls.Add(Office.MsoControlType.msoControlButton, Type.Missing, Type.Missing, Type.Missing, True), Office.CommandBarButton)
With btnCommandBarMenu
.BeginGroup = True
.Style = MsoButtonStyle.msoButtonIconAndCaption
.Caption = "File TNRP Email"
.Tag = "File TNRP Email"
.Picture = IPictureDisp.FromImage(My.Resources.label16)
.Mask = IPictureDisp.MaskFromImage(My.Resources.label16)
End With
AddHandler btnCommandBarMenu.Click, AddressOf btn_CommandBarMenuClick
End Sub
Sub Application_ItemContextMenuDisplay(ByVal CommandBar As Microsoft.Office.Core.CommandBar, ByVal Selection As Microsoft.Office.Interop.Outlook.Selection)
btnContextMenu = CommandBar.Controls.Add(Office.MsoControlType.msoControlButton, Type.Missing, Type.Missing, Type.Missing, True)
With btnContextMenu
.BeginGroup = True
.Visible = True
.Style = MsoButtonStyle.msoButtonIconAndCaption
.Caption = "File TNRP Email"
.Tag = "File TNRP Email"
.Picture = IPictureDisp.FromImage(My.Resources.label16)
.Mask = IPictureDisp.MaskFromImage(My.Resources.label16)
End With
AddHandler btnContextMenu.Click, AddressOf btn_ContextMenuClick
End Sub
发送电子邮件后,应用程序运行良好。但是当我点击按钮时,插件会触发 2 次,当我使用上下文菜单时,它也会触发 2 次。
知道为什么会这样吗?
【问题讨论】:
标签: vb.net vsto outlook-addin