我想在MDI父窗体中添加一个图片,就是如果没有子窗体打开就显示这张图片,如果打开了子窗体就显示子窗体,但现在打开了子窗体之后图片还是会显示,怎么才能把图片放在子窗体的下面?

解决方案 »

  1.   

    这个我做过,但忘了,好像不是一张图片的问题。        /// <summary>
            /// 添加一个窗体
            /// </summary>
            /// <param name="x"></param>
            public void AddForms(XtraForm x)
            {
                if (x == null)
                {
                    x = new XtraForm();
                }
                this.pictureEdit1.Visible = false;
                x.MdiParent = this;
                x.Show();
            }        /// <summary>
            /// 关于在什么时候显示背景图片
            /// </summary>
            private void showBackImage()
            {
                if (this.MdiChildren.Length == 0)
                {
                    this.pictureEdit1.Visible = true;
                    return;
                }            foreach (XtraForm xf in this.MdiChildren)
                {
                    if (xf.Visible)
                    {
                        return;
                    }
                }
                this.pictureEdit1.Visible = true;
            }
    呃找到了,以前做的一个项目,用的控件是DEV。不过这个跟标准控件的语法差别不大,应该能看懂吧。
      

  2.   

    this.pictureEdit1.Visible 为主窗体的填充图。
      

  3.   

    试试下面的代码,来自http://bingning.net/free/source/form/mdibackgroundimage.html//在背景中显示图片
     Bitmap back = new Bitmap("back.bmp"); //MDI父窗体的Load Event Handle
     private void ParentForm_Load(object sender, System.EventArgs e)
     {
         this.IsMdiContainer = true;
         //取得MdiClient
         System.Windows.Forms.MdiClient mc = GetMdiClient(this);
         //增加MdiClient的Paint和Resize Event Handle
         mc.Paint += new PaintEventHandler(MdiClient_Paint);
         mc.Resize += new EventHandler(MdiClient_Resize);
     } private void MdiClient_Paint(object sender, PaintEventArgs e)
     {
         System.Windows.Forms.MdiClient mc =
             (System.Windows.Forms.MdiClient) sender;
         //将图片按照符合Client领域大小的形式显示
         e.Graphics.DrawImage(back, mc.ClientRectangle);
     }
     
     private void MdiClient_Resize(object sender, EventArgs e)
     {
         System.Windows.Forms.MdiClient mc =
             (System.Windows.Forms.MdiClient) sender;
         //调用Paint事件
         mc.Invalidate();
     } /// <summary>
     /// 查找窗体的MdiClient控件并返回
     /// </summary>
     /// <param name="f">查找MdiClient控件的窗体</param>
     /// <returns>查询到的 MdiClient控件</returns>
     public static System.Windows.Forms.MdiClient 
         GetMdiClient(System.Windows.Forms.Form f)
     {
         foreach (System.Windows.Forms.Control c in f.Controls)
             if (c is System.Windows.Forms.MdiClient)
                 return (System.Windows.Forms.MdiClient) c;
         return null;
     }
      

  4.   

    好像winform中MDI父窗体中的控件一定会在自窗体之前,无论你怎么把自窗体制顶(我之前也遇到过),我的解决方法就是背景如果要切换,只能切换父窗体中的背景了,根据条件切换,以上是我的个人理解,如果有其他的方法一起学习~
      

  5.   

    或者,还有一种方法就是用一个MDI子窗体用你的pictureBox填充,然后一直显示这个子窗体,作为背景一样,其他的窗体都在这个窗体的上边,不过这样的不好的地方是你要去掉这个窗体的最大最小化等按钮和边框,并且要设置大小,否则其他的mdi子窗体在最大最小切换的时候也会影响这个背景。
    等待更好的解决方法。
      

  6.   


    关键是什么时候调用showBackImage呢?
      

  7.   

    主要逻辑是看看还有没有子窗体存在,如果没有就SHOW。因为用了DEV的特殊控件,子窗体是会完全挡住主窗体的MDI窗口的。