Catch WindowTurnedToPage Event in a Visio AddIn project

让人想犯罪 __ 提交于 2019-12-20 07:43:14

问题


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?


回答1:


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.




回答2:


This may look stupid, but i foud the answer, and i post it for anyone who find that a problem to pass it. The diiference bettwen the wrong way and thee good one is simple:

Wrong:Application.Window.WindowTurnedToPage += new Visio.EWindow_WindowTurnedToPageEventHandler(Window_WindowTurnedToPage);

Correct: Application.ActiveWindow.WindowTurnedToPage += new Visio.EWindow_WindowTurnedToPageEventHandler(Window_WindowTurnedToPage);

I need to mention that if you use the second implementation, it won't work on InternalStartup(). So you need to implement it after the initialize of the window.



来源:https://stackoverflow.com/questions/49439942/catch-windowturnedtopage-event-in-a-visio-addin-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!