none
Arrange All - Multiple Monitors RRS feed

  • Question

  • Using Word 2010 and VS 2010

    Looking for an 'Arrange All' routine to perform the following
    when 2 documents are loaded:

    If mulitple monitors, place the 1st document in the current monitor and maximize it.
    Place the next document in the next monitor and maximize it.

    Thanks


    Tim


    • Edited by Tim_Shaf Saturday, October 6, 2012 3:34 PM
    Saturday, October 6, 2012 3:33 PM

Answers

  • Although .NET Framework provides access to system screens, we don't have a way to move window across screens.  Screen class provides ways to
    Get which screen a point is in;

    which screen a control is in;

    which screen a handle is in;

    which screen a rectangle is in.  All of them are queries. Not setting.

    Looking through Window class in Word object model, we can set its state, but could not move it.


    Forrest Guo | MSDN Community Support | Feedback to manager

    • Proposed as answer by Forrest GuoModerator Friday, October 19, 2012 8:16 AM
    • Marked as answer by Tim_Shaf Friday, October 19, 2012 11:25 AM
    Friday, October 19, 2012 8:16 AM
    Moderator

All replies

  • Hi Tim_Shaf,

    Thanks for posting in the MSDN Forum.

    If mulitple monitors, place the 1st document in the current monitor and maximize it. Place the next document in the next monitor and maximize it.

    Would you please clarify this scenario more detailed. Can I consider that two document on the different machine?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, October 8, 2012 6:39 AM
    Moderator
  • Tom,
    Thanks for the reply.

    The current ArrangeAll splits the screen and stacks the 2 documents horizontally.
    When there are 2 moniotors, I would like to maximize and display each document in each monitor.

    Below is the code I have put together.

    Seems to work except I need to determine which screen the active document is in
    and try to avoid moving it. I need to do more testing but I think this code always moves
    the activedocument to the primary screen.

    Thanks Again

    Friend Sub ArrangeAll(ByVal App As Word.Application)
      If App.Documents.Count < 2 Then Exit Sub
      Dim Lefts As List(Of Integer) = (From c As Screen In
        Screen.AllScreens Select c.WorkingArea.X).ToList
      Dim Widths As List(Of Integer) = (From c As Screen In
        Screen.AllScreens Select c.WorkingArea.Width).ToList
      Dim i As Integer = 0
      Dim l As List(Of Word.Document) = 
        GetDocsOrderByActiveDocFirst(App)
      For Each d As Word.Document In l
          d.ActiveWindow.WindowState = 
             Word.WdWindowState.wdWindowStateNormal
          d.ActiveWindow.Left = Lefts(i Mod Lefts.Count)
          d.ActiveWindow.Width = Widths(i Mod Lefts.Count)
          d.ActiveWindow.WindowState = 
             Word.WdWindowState.wdWindowStateMaximize
          i += 1
      Next
      l(1).Activate() : l(0).Activate()
      l = Nothing
    End Sub
    Private Function GetDocsOrderByActiveDocFirst(
      ByVal App As Word.Application) _
      As List(Of Word.Document)
    Dim l As List(Of Word.Document) =
      (From d As Word.Document In App.Documents).ToList
    Do While Not l.First Is App.ActiveDocument
      Dim doc As Word.Document = l.First
      l.Remove(doc) : l.Add(doc) 
      'Moves 1st doc to end of list
    Loop
    Return l
    End Function


    Tim

    Monday, October 8, 2012 11:27 PM
  • How can I determine the screen of the activedocument?

    Thanks


    Tim

    Tuesday, October 9, 2012 1:41 PM
  • Hi Tim_Shaf,

    How can I determine the screen of the activedocument?

    I never see there have any properties which related to Screen. In PIA all of the document will be considered in the same monitor. I’m wondering whether there have a way to control it. And I don’t think it need to consider if the monitors display the screen come from same machine. I think whether you want to handle different windows of the document in the same monitor.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, October 10, 2012 7:09 AM
    Moderator
  • Although .NET Framework provides access to system screens, we don't have a way to move window across screens.  Screen class provides ways to
    Get which screen a point is in;

    which screen a control is in;

    which screen a handle is in;

    which screen a rectangle is in.  All of them are queries. Not setting.

    Looking through Window class in Word object model, we can set its state, but could not move it.


    Forrest Guo | MSDN Community Support | Feedback to manager

    • Proposed as answer by Forrest GuoModerator Friday, October 19, 2012 8:16 AM
    • Marked as answer by Tim_Shaf Friday, October 19, 2012 11:25 AM
    Friday, October 19, 2012 8:16 AM
    Moderator