Search code examples
c#eventsvisiooffice-addinsvisual-studio-addins

Catch WindowTurnedToPage Event in a Visio AddIn project


I'm trying to execute some code when the user swap between the pages of a visio window. So i tried to catch the WindowTurnedToPage event, but it simply don't work. Other events from his family can be catched, and they respond when they should. But WindowTurnedToPage and BeforeWindowPageTurn don't respond.

private void InternalStartup()
    {
        this.Startup += new System.EventHandler(ThisAddIn_Startup);
        this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        Application.Window.WindowTurnedToPage +=  new Visio.EWindow_WindowTurnedToPageEventHandler(Window_WindowTurnedToPage);
    }

    private void Window_WindowTurnedToPage(Visio.Window Window)
    {
        MessageBox.Show("Page changed");
    }

Please any help will be certain appreciate. What shoud ito to catch the Page Turn event?


Solution

  • I think you could use Application.WindowTurnedToPage.

    This will trigger for all page switches in the application.

    Your first version, Application.Window.WindowTurnedToPage did not work because Application.Window is main application window (i.e. frame window - not a drawing window), so it does not have any pages.

    The second version Application.ActiveWindow.WindowTurnedToPage may have a flaw - it will bind your event to the window that was active when you executed your code. If later on, you open another file, your code will not trigger event for that file's window.

    However, if you want to capture page switches only for a single window, that might be okay.