How to change the background color for an MDI parent form in Visual C#?

Follow below Steps:

Step:1-Create a new Visual C# Windows application.By default Form1 is created.
Step:2-Click the form -> on the View menu -> select Properties Window to view the properties for the form.
Step:3-Set BackColor property to the color that you want.
Step:4-Set the IsMDIContainer property to True.
Step:5-Set the WindowState property to Maximized.
Step:6-Then Double-click the form to view its code window.
Step:7-Copy the below code and paste into form’s load event.

MdiClient ctlMDI;

// Loop through all of the form's controls looking
// for the control of type MdiClient.
foreach (Control ctl in this.Controls)
      // Attempt to cast the control to type MdiClient.
      ctlMDI = (MdiClient) ctl;

      // Set the BackColor of the MdiClient control.
      ctlMDI.BackColor = this.BackColor;
   catch (InvalidCastException exc)
      // Catch and ignore the error if casting failed.

// Display a child form to show this is still an MDI application.
Form2 frm = new Form2();
frm.MdiParent = this;
Step:8-On the Project menu -> Add Windows Form.
Step:9-Accept the default name Form2.cs, and then click Open.
Step:10-Finally press F5 to run the application.
Note:-That the background color of the form changes to the color that the Application
Background color is set to in Control Panel.

About the Author