none
Making a Form child to the Word ActiveDocument/Application Window...

    Question

  • Hi all,

     

    I have only one window form in a word template project. Question is, how can i hook it up with the active document or word application window? programmatically using c#. If i minimize the document window, the form also minimizes.

     

    Thanks in advance.

    Friday, June 01, 2007 5:32 PM

Answers

  • Hi Raza,

    In my opinion, you can handle the event "this.Application.WindowSize". In the handle function, you can change the form's state by judging the windowstate of the word-window. Codes like these:

    Code Snippet

    Form1 myForm = null;

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
     {
         this.Application.WindowSize += new Microsoft.Office.Interop.Word.ApplicationEvents4_WindowSizeEventHandler(Application_WindowSize);
                myForm = new Form1();
                myForm.Show();
     }

     

    void Application_WindowSize(Microsoft.Office.Interop.Word.Document Doc, Microsoft.Office.Interop.Word.Window Wn)
     {
         switch (this.Application.ActiveWindow.WindowState)
         {
             case Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateMinimize:
                 myForm.WindowState = FormWindowState.Minimized;

                break;

            case Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateNormal:
                 myForm.WindowState = FormWindowState.Normal;
                 break;

            default:

                break;
          }
     }

     

     

    Wednesday, June 06, 2007 8:29 AM
    Moderator

All replies

  • Hi Raza,

    In my opinion, you can handle the event "this.Application.WindowSize". In the handle function, you can change the form's state by judging the windowstate of the word-window. Codes like these:

    Code Snippet

    Form1 myForm = null;

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
     {
         this.Application.WindowSize += new Microsoft.Office.Interop.Word.ApplicationEvents4_WindowSizeEventHandler(Application_WindowSize);
                myForm = new Form1();
                myForm.Show();
     }

     

    void Application_WindowSize(Microsoft.Office.Interop.Word.Document Doc, Microsoft.Office.Interop.Word.Window Wn)
     {
         switch (this.Application.ActiveWindow.WindowState)
         {
             case Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateMinimize:
                 myForm.WindowState = FormWindowState.Minimized;

                break;

            case Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateNormal:
                 myForm.WindowState = FormWindowState.Normal;
                 break;

            default:

                break;
          }
     }

     

     

    Wednesday, June 06, 2007 8:29 AM
    Moderator
  • Thanks Ji Zhou,

     

    I will try your code BUT one of my actual requirement is to use my windows form always at the top of my Word Template Document, if in use. I can able to place it somewhere on the document screen and able to work in the document as well. I dont want it to go behind the document window when i click inside the document, as it behaves currently. I am looking similar to the help window, as it always at the top.

     

    Thanks,

     

    -Syed

    Thursday, June 07, 2007 7:24 PM
  • Hi Syed,

    Sorry for misunderstanding. If you are using Word2003, I think you can use Action Pane to achieve that, and if Word2007, Custom Task Pane will be a better choice. To see more about Action Pane and Custom Task Pane, refer following links:

    http://msdn2.microsoft.com/en-us/library/h6b1d03x(VS.80).aspx

    http://msdn2.microsoft.com/en-us/library/aa722570.aspx

     

     

    Thanks

    Ji

    Friday, June 08, 2007 2:33 AM
    Moderator
  • Hi Ji,

    I am already using a custom task pane with multiple tabs on it and almost fully occupied. From an Smart Tag action item i am looking forward to display a multiline text in a window's form that i can place somewhere on the screen (need always on the top of the word document application like help window). Also trying to accomplish  a task from another action menu item which uses the task pane objects hopefully get it through ROT as its a commnunication between document and addin.

     

    Thanks,

    -Syed

    Friday, June 08, 2007 6:13 PM