这是我在此代码中的代码我在Microsoft Outlook检查器中成功添加了按钮,但是当在Outlook检查器中打开新邮件时(通过双击收件箱中)按钮可以添加但是如果我再次单击相同的主,则在Outlook中添加两个按钮检查员所以在调用事件之前我想删除或删除上一个按钮
如何从Inspector中删除按钮?
Private Sub inspectors_NewInspector(ByVal Inspector As Microsoft.Office.Interop.Outlook.Inspector) Handles inspectors.NewInspector
Try
Private MenuBar As Office.CommandBar
Private ButtonOne As Office.CommandBarButton
Dim mailItem As outlook.MailItem = TryCast(Inspector.CurrentItem, outlook.MailItem)
If Not (mailItem Is Nothing) Then
Try
MenuBar = Inspector.CommandBars.Add("Mail", Office.MsoBarPosition.msoBarTop, False, True)
MenuBar.Visible = True
MenuBar.Protection = Microsoft.Office.Core.MsoBarProtection.msoBarNoCustomize
ButtonOne = MenuBar.Controls.Add(Office.MsoControlType.msoControlButton, , , , True)
'ButtonOne.Caption = "Archive"
'ButtonOne.Tag = "My Button"
Dim newIcon As Icon = My.Resources.iiMS_32x32
Dim newImageList As New ImageList
newImageList.Images.Add(newIcon)
Clipboard.SetDataObject(newImageList.Images(0), False)
With ButtonOne
.Style = Office.MsoButtonStyle.msoButtonIconAndCaption
.Caption = ButtonCaption
.FaceId = 65
.Tag = menuTag
ButtonOne.PasteFace()
End With
Try
AddHandler ButtonOne.Click, AddressOf ButtonClick
Catch ex As Exception
writelog("Error Occured in preview windows while adding a Handler, Error: " & ex.Message)
MessageBox.Show("Application Error, Please Check Error Log", strCaption, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Catch ex As Exception
writelog(ex.Message)
writelog(ex.StackTrace)
End Try
End If
Catch ex As Exception
writelog(ex.Message)
writelog(ex.StackTrace)
End Try
End Sub
答案 0 :(得分:1)
针对这些情况的最佳方法是实现Inspector Wrapper。这样,您就可以拥有每个打开项目窗口的专用实例,并可以单独跟踪控制状态和可见性。您仍然需要添加逻辑,以检测或添加您要使用的工具栏控件。参见:
为Outlook 2010开发Inspector Wrapper http://msdn.microsoft.com/en-us/library/ff973716.aspx