设置MDI父窗口背景图片

 这两天由WebForm转了过来WinForm,很多东西都要学,都要去适应。

 

前天研究设置MDI父窗口的背景图片,在GOOGLE找了一片,是有的,不过觉得代码有改进的地方,就自己改了,现在贴出来,跟大家一起分享一下!

 

 

 1 using System;
 2 using System.Drawing;
 3 using System.IO;
 4 using System.Windows.Forms;
 5 
 6 namespace TextWinForm
 7 {
 8     public partial class MainForm : Form
 9     {
10         public MainForm()
11         {
12             InitializeComponent();
13             
14             try
15             {
16                 string imagepath = Application.StartupPath + @"\Images\backGround.jpg";
17                 foreach (Control ct in this.Controls)
18                 {
19                     //if (ct.GetType().Equals(typeof(MdiClient)) && (File.Exists(imagepath)))
20                     if (ct.GetType().ToString().Equals("System.Windows.Forms.MdiClient"&& (File.Exists(imagepath)))
21                     {
22                         ((MdiClient)ct).BackgroundImage = new Bitmap(imagepath);
23                     }
24                  }
25              }
26              catch (Exception ex) { MessageBox.Show(ex.Message); }
27         }
28     }
29 }

 

 

posted on 2008-08-18 11:13  BadTree  阅读(2389)  评论(0编辑  收藏  举报