程晓晖

博客园 首页 新随笔 联系 订阅 管理

在WinForm编程中大家可以想要在MDI父窗体中插入一张背景图片,下面给出实现方法:
首先定义一个MdiClient变量
private System.Windows.Forms.MdiClient mdiClient;在Mdi父窗体的构造函数中添加如下代码:
            //
            //准备获取MdiClient
            //
            int iCnt=this.Controls.Count;
            for(int i=0;i<this.Controls.Count;i++)
            {
                if(this.Controls[i].GetType().ToString()=="System.Windows.Forms.MdiClient")
                {
                    this.mdiClient=(System.Windows.Forms.MdiClient)this.Controls[i];
                    break;
                }
            }
            string fbImage = Application.StartupPath + "\\Images\\backGround.jpg";
            if(File.Exists(fbImage))
            {
                Bitmap bm = new Bitmap(fbImage);
                this.mdiClient.BackgroundImage = bm;
            }其中fbImage是你要设置的背景图片

posted on 2010-11-22 18:43  fumen  阅读(1522)  评论(1编辑  收藏  举报