项目中有一个主窗体MainForm ,并直接在属性中设置IsMdiContainer = true; 
在MainForm窗体上放置一个按钮Button1,点击Button1弹出子窗体Form2,
并且在显示Form2之前设置Form2的MdiParent属性值为Mainform窗体。运行后 点击MainForm窗体上的Button1按钮,弹出Form2,。但是Form2窗体总是显示在Button2的后面,如何让Form2显示在最前面?效果如图:

解决方案 »

  1.   

    你还是改改布局吧,一般没你这么布局的,要么从菜单打开子窗口,或者把主窗体的组件放到一个容器中,比如panel然后这是panel的dock,然后剩余的部分,就是容纳子窗体的
      

  2.   


       Form2 frm=new Form2();
       frm.MdiParent = this;
       frm.TopMost = true; //加上这句
       topMostForm.Show();
      

  3.   

    using System.Runtime.InteropServices;[DllImport("user32")]
    public static extern int SetParent(int hWndChild, int hWndNewParent);//temp2是你的子form
    temp2.MdiParent = this;
    temp2.Show();
    SetParent((int)temp2.Handle, (int)this.Handle);
      

  4.   

    最后错了,改为:
    frm.Show();
      

  5.   

    晕,哪有这样弄的,要不弄TOOLBAR要不弄MENU来弹出新窗口,