在.net中更改MDI容器表单的背景颜色或背景图像

我需要在我的应用程序中更改mdi父级的背景颜色或背景图像。 我尝试更改背景颜色或指定背景图像,它将无法正常工作。 我也尝试循环窗体中的控件以获取mdiclient并更改其背景颜色,也是同样的结果。

也许这会有所帮助? http://support.microsoft.com/kb/319465

Private ClientControl As MdiClient Public Sub New() InitializeComponent() ClientControl = Nothing For Each Ctl As Control In Me.Controls ClientControl = TryCast(Ctl, MdiClient) If ClientControl IsNot Nothing Then Exit For Next End Sub 'iN FORM LOAD ClientControl.BackColor = Color.Cyan 

如果您正在做一个简单的颜色然后尝试下面的代码,如果您尝试设置图像,那么您可以使用BackgroundImageLayout BackgroundImage

  MdiClient ctlMDI; foreach (Control ctl in this.Controls) { try { ctlMDI = (MdiClient)ctl; // Set the BackColor of the MdiClient control. ctlMDI.BackColor = Color.DarkRed; } catch (InvalidCastException exc) { // Catch and ignore the error if casting failed. } } 

试试这个,它有效。

 foreach (Control control in this.Controls) { // #2 MdiClient client = control as MdiClient; if (!(client == null)) { // #3 client.BackColor = GetYourColour(); // 4# break; } }