1. 程式人生 > >C#的winform中MDI 父窗體改變背景色

C#的winform中MDI 父窗體改變背景色

MdiClient ctlMDI;

// Loop through all of the form's controls looking
// for the control of type MdiClient.
foreach (Control ctl in this.Controls)
{
   try
   {
      // 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;
frm.Show();