2012-02-14 3 views
1

이 질문에 대한 대답은 이미 here이지만 질문에 만족하지 않습니다.Outlook 컨텍스트 메뉴 항목 클릭 횟수가 여러 번 발생했습니다

현재 Outlook에 사용자 지정 상황에 맞는 메뉴를 추가하고 있습니다. 다음과 같이 코드입니다 : 내가 응용 프로그램을 실행할 때

void Application_ItemContextMenuDisplay(Microsoft.Office.Core.CommandBar CommandBar, Microsoft.Office.Interop.Outlook.Selection Selection) 
    { 
     if (Online) 
     { 
      foreach (string category in FilingRuleManager.FilingRuleCategories) 
      { 
       Office.CommandBarPopup cb = CommandBar.Controls.Add(Office.MsoControlType.msoControlPopup, missing, missing, missing, true) as Office.CommandBarPopup; 
       cb.BeginGroup = true; 
       cb.Visible = true; 
       cb.Tag = MENUNAME; 
       cb.Caption = category; 
       //now add the filing rules as a sub menu 
       foreach (FilingRuleDB rule in FilingRuleManager.FilingRules.Values) 
       { 
        if (rule.RuleCategory == category) 
        { 
         Office.CommandBarButton cbSub = cb.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true) as Office.CommandBarButton; 
         _FilingRules.Add(cbSub); 
         cbSub.Visible = true; 
         cbSub.Caption = rule.RuleName; 
         cbSub.Tag = rule.FilingRuleID.ToString(); 
         cbSub.Click += new Office._CommandBarButtonEvents_ClickEventHandler(FilingRules_Click); 
        } 
       } 
      } 
     } 
    } 

가, 때마다 내가 Outlook에서 상황에 맞는 메뉴를 클릭 처리기 (FilingRules_Click)이 여러 번 있다는 해고를 보여줍니다. 그래서 내가 3 번 마우스 오른쪽 버튼을 클릭하면 처리기가 3 번 실행됩니다.

위에서 링크 된 질문의 해킹보다이를 달성하는 더 좋은 방법이 있어야합니다.

나는 시도했다 :

  1. 단지를 추가하기 전에 CommandBarButtons 제거 - 그러나 그들은 존재하지 않는다! Outlook 컨텍스트 메뉴가 숨겨져있을 때마다 사용자 지정 항목이 자동으로 제거됩니다.
  2. 목록에 컨트롤을 저장하고 처리기를 제거하려고 시도하면 메뉴가 숨겨진 후에 더 이상 존재하지 않는 단추가 AV에 제공됩니다.
  3. 나를 위해 ItemContextMenuHidden() 이벤트가 연결되어 있지 않습니다. 그렇지 않으면 연결을 시도했을 것입니다.
  4. 추가 기능이 시작될 때 (즉, ItemContextMenuDisplay() 처리기없이 한 번만) 항목을 추가하지만 메뉴가 표시 될 때 항목이 항상 지워지므로 항목이 표시되지 않습니다.

누구나 다른 제안이 있습니까?

답변

2

문제가 해결되었습니다.

  1. 클래스 레벨 정적 변수
  2. Outlook.Application 첨 이벤트 ContextMenuClose로서 해당 명령을 정의한다.

    outlookInstance.ContextMenuClose += new ApplicationEvents_11_ContextMenuCloseEventHandler(outlookInstance_ContextMenuClose); 
    
  3. 코드

    void outlookInstance_ContextMenuClose(OlContextMenu ContextMenu) 
    { 
        if (ContextMenu == OlContextMenu.olItemContextMenu) 
        { 
         ContextIndexButton.Click -= new _CommandBarButtonEvents_ClickEventHandler(<your method>); 
         ContextIndexButton = null; 
        } 
    } 
    
+0

재미있는 같은 방법을 구현, 나는이 내 말을 다 할 것입니다. 감사 – Simon

관련 문제