Friday, February 20, 2009

How to set backgroud color of MDI

Since the property is not available at design time, all you need is a simple loop through controls (probably in load event) to set the background color of mdi window.

foreach (Control ctrl in Controls)
  if (!(ctrl is MdiClient)) continue;
  string colorName = ConfigurationManager.AppSettings["Dialog.BackColor"];
  if (colorName == null) continue;
  Color color = Color.FromName(colorName);
  //checks if color is transparent, mdiclient.backcolor doesn't support transparent colors
  if (color.A != 0)
       ctrl.BackColor = Color.FromName(colorName);

No comments: