Search code examples
c#powerpointvstooffice-addinspowerpoint-addins

VSTO C# in Powerpoint: WindowSelectionChange Event


I am new to VSTO and C# and have a question regarding events. I'm trying to fire an event when the user selects something within PowerPoint (e.g. a shape, slide, etc).

I found a working solution for VBA in the Office documentation here and some more info for a Word selection handler here, however I'm clueless on how and where to add it in my ThisAddIn.cs context.

I'm currently working from a fresh C# PowerPoint VSTO Addin Blank C# PowerPoint VSTO Addin

Any pointers into the right direction are highly welcome. Thanks!


Solution

  • Found this and it works:

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        this.Application.WindowSelectionChange += Application_WindowSelectionChange;
    
    }
    
    private void Application_WindowSelectionChange(PowerPoint.Selection Sel)
    {
        //throw new NotImplementedException();
        MessageBox.Show("Hello");
    }