How to change the background color for an MDI parent form in Visual C#
This article demonstrates how to programmatically change the background color for a multiple-document interface (MDI) parent form by using Visual C#.
When you use a Windows Form as an MDI parent form, the Application Background color setting in Windows Control Panel, not the form's BackgroundColor property, determines the background color of the form. The following steps demonstrate how to programmatically change the MDI parent form's background color to another color.
Create a Sample Windows Application by Using Visual C#
Create a new Visual C# Windows application. Form1 is created by default. Click the form, and then, on the View menu, select Properties Window to view the properties for the form. Set the
property to the color that you want (such as Blue).
property to True. Note that the background color of the form changes to the color that the Application Background color is set to in Control Panel. Set the WindowState property to Maximized. Double-click the form to view its code window. Paste the following code into the form's Load event handler:
foreach (Control ctl in this.Controls)
ctlMDI = (MdiClient) ctl;
ctlMDI.BackColor = this.BackColor;
catch (InvalidCastException exc)
Form2 frm = new Form2();
frm.MdiParent = this;
On the Project menu, click Add Windows Form. Accept the default name Form2.cs
, and then click Open.
Press F5 to run the application. Note that the MDI parent form loads and has a blue background.