WinForm中如何设置MDI父窗体的背景图片

在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 @ 2006-05-14 17:41  温伟鹏  阅读(3590)  评论(5编辑  收藏  举报