none
Catch Activate-Event of any inspector RRS feed

  • Question

  • Hello,

    How can I catch the Activate-Event of any Inpector, when I open multiple inspectors?

    Regards,

    Cheng

    Thursday, November 9, 2017 4:07 PM

Answers

All replies

  • Hello,

    The following code would work for any inspector.

            Outlook.Inspector myInspector;
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                Application.Inspectors.NewInspector += Inspectors_NewInspector;
            }
       	private void Inspectors_NewInspector(Outlook.Inspector Inspector)
            {
                myInspector = Inspector;
                ((Outlook.InspectorEvents_Event)myInspector).Activate += new Outlook.InspectorEvents_ActivateEventHandler(myInspector_Activate);
            }
    
            private void myInspector_Activate()
            {
                Object item = myInspector.CurrentItem;  
            }

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 10, 2017 2:06 AM
    Moderator
  • Hello,

    Thank you for your quick answer.

    I open multiple Inspectors (Mails) and I want to read the Subject for each activated Inspector. When I switch to anohter Inspector Window I get always the Subject of last opend Inspector.How can I fix this problem.

    Thanks

    Cheng

    Friday, November 10, 2017 5:18 PM
  • You can use Application.ActiveInspector to access currently activated Inspector window.

     private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        Application.Inspectors.NewInspector += Inspectors_NewInspector;
    }
    
    private void Inspectors_NewInspector(Outlook.Inspector Inspector)
    {
        ((Outlook.InspectorEvents_Event)myInspector).Activate += new Outlook.InspectorEvents_ActivateEventHandler(myInspector_Activate);
    }
    
    private void myInspector_Activate()
    {
        Inspector inspector = Application.ActiveInspector;
        MailItem item = inspector.CurrentItem as MailItem;
        if(item != null)
        {
            string subject = item.Subject;
        }
     }


    Friday, November 10, 2017 11:20 PM
  • Hello Cheng,

    In that situation, please implement inspector wrapper for mail item.

    Please visit

    Developing an Inspector Wrapper for Outlook 2010

    How to: Implement a Wrapper for Inspectors and Track Item-Level Events in Each Inspector

    You could download code sample from Outlook 2010: Developing an Inspector Wrapper

    To get subject of each mailitem at inspector Activate event, you could add the following code in the MailItemWrapper.cs:

            protected override void Activate()
            {
                base.Activate();
                System.Windows.Forms.MessageBox.Show(Item.Subject);
            }
    

    You may download the sample from

    https://1drv.ms/u/s!AkcxDWH1nFmJpVLdzvKUgHVuKVDI

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 13, 2017 2:09 AM
    Moderator
  • Hello Celeste,

    your solution works fine. Thanks a lot.

    Regards

    Cheng

    Thursday, November 23, 2017 2:15 PM