MDI窗体改变背景
这样的代码不能用于BACKPANEL
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
///
<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 ;
}
private void 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>
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 ;
}
private void Form1_Load( object sender, EventArgs e)
{
// 查找MdiClient
System.Windows.Forms.MdiClient mc = GetMdiClient( this );
if (mc != null )
{
// 更改背景色,重新描绘
mc.BackColor = Color.Red ;
mc.Invalidate();
}
}