none
Set position to display a new document at RRS feed

  • Question

  • Hi all;

    Is there a way to set where a new document is displayed on the window at? If I set Document.ActiveWindow.Left/Top before calling Document.Activate() then the settings are ignored. If I call after it works, but the document is displayed, then jumps.

    ??? - thanks - dave


    Very funny video - What's your Metaphor?
    Monday, March 21, 2011 11:38 PM

All replies

  • Hello Dave,

    Thanks for posting. By making a test on my side, I am not able to reproduce this issue on my side. I write the following code in the click event handler of a button. This button is added to ribbon. There are two documents opened currently (Document1 and Document2). Now the Document1 is the active document. When I click the button in Document1, the position of Document2 has been changed.

    The code as below,

            private void button1_Click(object sender, RibbonControlEventArgs e)

            {

                try

                {

                    Word.Document document2= Globals.ThisAddIn.Application.Documents["Document2"];

     

                    document2.ActiveWindow.Left = 200;

                    document2.ActiveWindow.Top = 200;

                    document2.ActiveWindow.Width = 300;

                    document2.ActiveWindow.Height = 300;

                }

                catch (Exception ex)

                {

                    MessageBox.Show(ex.ToString());

                }

            }

    Please see if there is a difference between us. If yes, please feel free to correct me. Have a nice day.


    Bessie Zhao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 22, 2011 9:27 AM
  • Hi;

    I think in your example both documents are already created. In my case I am creating document2 and want to set the location where it is first displayed.

    I am calling Application.Documents.Open() and want to position that newly opened document's window before it is displayed on the screen.

    thanks - dave


    Very funny video - What's your Metaphor?
    Thursday, March 24, 2011 3:48 PM
  • Hello again Dave,

    Yes, you are right. The scenario in my side is that these two documents have been opened. From what you side, I have done more test for this issue. Code like this,

                try
                {
                    Word.Document document2 = Globals.ThisAddIn.Application.Documents.Open(@"c:\test\1.docx");
                    document2.Application.WindowState = Word.WdWindowState.wdWindowStateNormal;
                    document2.ActiveWindow.Left = 200;
                    document2.ActiveWindow.Top = 200;
                    document2.ActiveWindow.Width = 300;
                    document2.ActiveWindow.Height = 300;

                    //Globals.ThisAddIn.Application.Selection.InsertFile(@"C:\Test\1.docx");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

    Please see if this could help you or not. If you have any concern on it, just feel free to follow up. Have a nice weekend.


    Bessie Zhao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, March 25, 2011 8:52 AM
  • Hi Bessie;

    I have tried this and I get the window showing up slightly below/right of the other window, then it jumps up to match.

    thanks - dave


    Very funny video - What's your Metaphor?
    Monday, April 4, 2011 4:59 PM
  • Hello again Dave,

    Unfortunately, I am not able to reproduce this issue (jump up) on my side. To narrow down this issue, you could do more test on your side by simpifying a project/steps and see if this issue also happens.

    By doing this test, we might get more information to ensure if this case is related to other parts. Have a nice day.


    Bessie Zhao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, April 6, 2011 8:50 AM