MDI窗体改变背景
这样的代码不能用于BACKPANEL
代码
///<summary>
/// 查找窗体的MdiClient控件并返回
///</summary>
///<param name="f">查找MdiClient控件的窗体</param>
///<returns>查找到的MdiClient控件</returns>
publicstatic 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;
returnnull;
}
privatevoid Form1_Load(object sender, EventArgs e)
{
//查找MdiClient
System.Windows.Forms.MdiClient mc = GetMdiClient(this);
if (mc !=null)
{
//更改背景色,重新描绘
mc.BackColor = Color.Red ;
mc.Invalidate();
}
}
/// 查找窗体的MdiClient控件并返回
///</summary>
///<param name="f">查找MdiClient控件的窗体</param>
///<returns>查找到的MdiClient控件</returns>
publicstatic 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;
returnnull;
}
privatevoid Form1_Load(object sender, EventArgs e)
{
//查找MdiClient
System.Windows.Forms.MdiClient mc = GetMdiClient(this);
if (mc !=null)
{
//更改背景色,重新描绘
mc.BackColor = Color.Red ;
mc.Invalidate();
}
}