그래서 메뉴 항목의 실제 선택 뒤에있는 이벤트가 여러 번 실행되는 것 외에는 상황에 맞는 메뉴가 작동합니다. 처음 클릭하면 한 번, 두 번, 세 번 발사됩니다. 그래서, 방금 전한 예제에서 3 번의 클릭으로 총 6 회 (1 + 2 + 3)의 해고를했을 것입니다. 왜 그런가요?내 Outlook 컨텍스트 메뉴 (추가 기능) 단추가 한 번의 클릭으로 여러 번 실행됩니다.
다음은 메뉴 항목을 만드는 방법에 대한 내 코드입니다. 나는 그것을 관련 조각들로 잘라 냈다. .Tag, .Visible 및 .Caption 속성과 같은 것을 생략했습니다. .NET 3.5 및 VS 2008을 사용하여이를 구축하고 있습니다.
감사합니다.
Private WithEvents ActiveExplorerCBars As Office.CommandBars
Private app As New Outlook.Application
Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
ActiveExplorerCBars = app.ActiveExplorer.CommandBars
AddHandler ActiveExplorerCBars.OnUpdate, AddressOf ActiveExplorerCBars_OnUpdate
End Sub
//This seems to get hit A LOT
Private Sub ActiveExplorerCBars_OnUpdate()
Dim bar As Office.CommandBar
If IgnoreCommandbarsChanges Then Exit Sub
bar = ActiveExplorerCBars.Item("Context Menu")
If Not bar Is Nothing Then
Dim addMenu As Boolean = False
//this For loop just makes sure the context is only available when the user right-clicks over a mail item
For Each mail As Outlook.MailItem In Application.ActiveExplorer().Selection
addMenu = True
Exit For
Next
If addMenu Then
AddContextDropdown(bar)
End If
End If
End Sub
Private Sub AddContextDropdown(ByVal ContextMenu As Office.CommandBar)
Dim RootPopup As Office.CommandBarPopup
Dim popupTaskItem As Office.CommandBarPopup
RootPopup = ContextMenu.FindControl(Type:=Office.MsoControlType.msoControlPopup, Tag:="Update task")
If RootPopup Is Nothing Then
ChangingBar(ContextMenu, Restore:=False)
RootPopup = ContextMenu.Controls.Add(Type:=Office.MsoControlType.msoControlPopup)
Dim thisTaskPopup As Office.CommandBarPopup
popupTaskItem = ContextMenu.FindControl(Type:=Office.MsoControlType.msoControlPopup, Tag:=task.EntryID)
If popupTaskItem Is Nothing Then
popupTaskItem = RootPopup.Controls.Add(Type:=Office.MsoControlType.msoControlPopup)
thisTaskPopup = popupTaskItem
AddActionButtons(thisTaskPopup)
End If
End If
End Sub
Private Sub AddActionButtons(ByVal puItem As Office.CommandBarPopup)
Dim puDeploy As Office.CommandBarPopup = puItem.Controls.Add(Type:=Office.MsoControlType.msoControlPopup)
Dim btnActionItem As Office.CommandBarControl = puDeploy.Controls.Add(Type:=Office.MsoControlType.msoControlButton)
Dim thisButton As Office.CommandBarButton = btnActionItem
AddHandler thisButton.Click, AddressOf OnContextClick
End Sub
//Click event
Public Sub OnContextClick(ByVal ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
//This messagebox shows once the first time, twice the second, 3 times, etc
MessageBox.Show("Clicked: " & ctrl.Caption)
End Sub
내가 잘 모르겠지만, 어쨌든, 어쩌면이 MSDN 예제 도움이 될 : http://msdn.microsoft.com/en-us/library/ms268864%28VS.80%29.aspx –
MA Hanin : 답장을 보내 주셔서 감사합니다.하지만이 코드는 상단에 메뉴 모음을 추가하는 데 사용됩니다. 오른쪽 클릭을위한 컨텍스트 메뉴를 추가하려고합니다. –
OnUpdate는 너의 것뿐만 아니라 술집에 대한 어떤 업데이 트에서도 호출됩니다 .... – tobrien