C# FAQ: How set the background of an MDI container window

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
CSharp-Online.NET:FAQs
edit

How set the background of an MDI container window?

A portion of this answer applies only to .NET version 1.1 and earlier. In .NET 2.0, the BackgroundImage property works properly. The BackColor property can be set as in the source code example below.

The area of an MDI container window is covered by an MdiClient control; consequently, Form.BackColor and Form.BackgroundImage are ineffective. Rather, find the MdiClient by iterating through the controls as in the following example:

private void Form_Load (object sender, System.EventArgs e)
{
   foreach (Control control in this.Controls)
   {
      if (control is MdiClient) // located it
      {
         control.BackColor = Color.Red;
         break;
      }
   }
}

In order to update the MDI background—for example, to position a logo when the window is resized—the program must handle the Paint event for the MdiClient.



Personal tools