在已有的form之上显示显示子form,

解决方案 »

  1.   

    /// <summary>
    /// 使这个窗口嵌入任何一个控件中
    /// </summary>
    public System.Windows.Forms.Control  MyDefineMdiParent
    {
    set
    {
    _ParentForm=value;
    int ParentStyle=GetWindowLong(_ParentForm.Handle,GWL_STYLE);
    ParentStyle=ParentStyle | WS_CHILD;
    SetWindowLong(this.Handle,GWL_STYLE,ParentStyle);
    SetParent(this.Handle,_ParentForm.Handle);
    SetWindowPos(this.Handle,
    HWND_TOP,
    _ParentForm.Left,
    _ParentForm.Top,
    _ParentForm.Width-10,
    _ParentForm.Height-10, 
    SWP_NOZORDER | SWP_NOACTIVATE | SWP_SHOWWINDOW);//
    }
    get{return _ParentForm;}
    }
      

  2.   

    接上文:
    #region API常数
    int HWND_TOP=0;
    int WS_CHILD=0x40000000;
    int GWL_STYLE=-16;
    int SWP_NOZORDER = 0x4;
    int SWP_NOACTIVATE = 0x10;
    #endregion#region API声明
    [DllImport("user32.dll")]
    public static extern int GetWindowLong (IntPtr hwnd,int index);

    [DllImport("user32.dll")]
    public static extern int SetWindowLong  (IntPtr hwnd,int index,int newValue);

    [DllImport("user32.dll")]
    public static extern int SetParent  (IntPtr childHwnd,IntPtr parentHwnd); [DllImport("user32.dll")]
    public static extern int SetWindowPos (IntPtr hwnd , int hWndInsertAfter , int x ,int y , int cx ,int cy , int wFlags );

    [DllImport("user32.dll")]
    public static extern int  GetClientRect(IntPtr hwnd , Rectangle  lpRect );

    [DllImport("user32.dll")]
    public static extern int  PostMessage(IntPtr hwnd , int wMsg  , int  wParam  , int lParam  );#endregion
      

  3.   

    http://expert.csdn.net/Expert/topic/2520/2520043.xml?temp=.947674
      

  4.   

    subform=new SubForm();
    subform.TopLevel=false;
    subform.Parent =this.panel1;