none
Word PageChange Event RRS feed

  • Question

  • Hi!

    I'm trying to include a label with The message "Page x of y" in a custom Task Pane. To this I need to know the current page and the total number of pages.

    Besides this I need to catch an event to update the label text as the user moves trough the document (using the scroll bar, mouse click or simply writing).

    Is there any way to do this in C#?

    Thanks in advance

     

     

     

     

     

    Tuesday, January 3, 2012 3:48 PM

Answers

  • Hi boavidag

    <<After reading your answer I'm affraid this is impossible to do...>>

    Very difficult, in any case, and not supported by VSTO or Office.

    The Windows API or VBA can be used to intercept keyboard events (keyboard hooks / keybindings) and possibly the Windows API for using the scrollbar. There have been a number of discussions here in the forum along a similar vein, but I don't think any of them provide a solution that you can "plug in" and use. You should find code examples about using the Windows API, though.


    Cindy Meister, VSTO/Word MVP
    Wednesday, January 4, 2012 2:59 PM
    Moderator

All replies

  • This may do it, or at least get you started:

    http://stackoverflow.com/questions/7502703/how-to-add-a-page-x-of-y-footer-to-word2007-doc-as-i-am-generating-it-using-c

    Tuesday, January 3, 2012 8:19 PM
  • Hi boavidag

    The ComputeStatistics method can give you the total number of pages in the document.

    The WordApplicaiton.Selection.Information method, with the appropriate argument, will return the page number of the page where the user has placed the cursor.

    There is no event that triggers when the display of the document content changes to show an additional page (as when the user is typing). Nor are there any events that fire during typing or scrolling.

    When the user clicks or uses the arrow keys to move the selection the WindowSelectionChange event is triggered.


    Cindy Meister, VSTO/Word MVP
    Wednesday, January 4, 2012 8:29 AM
    Moderator
  • Hi,

    thanks for you reply. In fact I already tryed that and now I can display the current page and total number of pages.

    The problem now is to get it updated as the user writes the content.

    Thanks

    Wednesday, January 4, 2012 9:53 AM
  • Hi Cindy!

    Thanks for your reply! At this moment I can get the total page count and the current page. The ComputeStatistics works just fine...

    I tried the WindowSelectionChange event, it works but I was looking for something more accurate. I need to display information on task pane which should be updated according to the content that the user is typing.

    After reading your answer I'm affraid this is impossible to do...

    Thanks.

    Wednesday, January 4, 2012 10:00 AM
  • Hi boavidag

    <<After reading your answer I'm affraid this is impossible to do...>>

    Very difficult, in any case, and not supported by VSTO or Office.

    The Windows API or VBA can be used to intercept keyboard events (keyboard hooks / keybindings) and possibly the Windows API for using the scrollbar. There have been a number of discussions here in the forum along a similar vein, but I don't think any of them provide a solution that you can "plug in" and use. You should find code examples about using the Windows API, though.


    Cindy Meister, VSTO/Word MVP
    Wednesday, January 4, 2012 2:59 PM
    Moderator