title: How to open word document inside form in windows application
body: <p>i need to open a word document in a panel control of Windows Forms Application to view/edit file and save.</p>
  
  <p>i use this statement :</p>
  
  <pre><code>    [DllImport("user32.dll")]
      public static extern int FindWindow(string strclassName, string strWindowName);
  
      [DllImport("user32.dll")]
      static extern int SetParent(int hWndChild, int hWndNewParent);
  
      [DllImport("user32.dll", EntryPoint = "SetWindowPos")]
      static extern bool SetWindowPos(
          int hWnd,               // handle to window
          int hWndInsertAfter,    // placement-order handle
          int X,                  // horizontal position
          int Y,                  // vertical position
          int cx,                 // width
          int cy,                 // height
          uint uFlags             // window-positioning options
      );
  
      [DllImport("user32.dll", EntryPoint = "MoveWindow")]
      static extern bool MoveWindow(
          int hWnd,
          int X,
          int Y,
          int nWidth,
          int nHeight,
          bool bRepaint
      );
  
      const int SWP_DRAWFRAME = 0x20;
      const int SWP_NOMOVE = 0x2;
      const int SWP_NOSIZE = 0x1;
      const int SWP_NOZORDER = 0x4;
      const int SWP_FRAMECHANGED = 0x20;
      ToolsComponents.MSWord word = new ToolsComponents.MSWord();
  
      private void toolStripButton2_Click(object sender, EventArgs e)
      {
          word.CreateWordDocument();
          word.OpenFile(@"C:\Users\ME\Documents\test.docx", true);
          int wordWnd = FindWindow("Opusapp", null);
          if (wordWnd != 0)
          {
              int ret = SetParent(wordWnd, pnlShowForm.Handle.ToInt32());
  
              //int ret2 = FindWindow("Opusapp", null);
              //ret = SetParent(wordWnd, pnlShowForm.Handle.ToInt32());
              SetWindowPos(wordWnd, pnlShowForm.Handle.ToInt32(), 0, 0, pnlShowForm.Bounds.Width - 20, pnlShowForm.Bounds.Height - 20, SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOMOVE | SWP_DRAWFRAME);
              MoveWindow(wordWnd, -5, -33, pnlShowForm.Bounds.Width + 10, pnlShowForm.Bounds.Height + 57, true);
          }
      }
  
      private void frmDocumentManager_FormClosing(object sender, FormClosingEventArgs e)
      {
          if (word != null)
          {
              word.CloseDoc(true);
              word.Quit();
          }
  </code></pre>
  
  <p>but this is not a good solution and have problem in runtime.
  in sometimes MS word and document started outside the form and i can't control this.</p>