Saturday 10 November 2012

How to Set the Back color for MDI Parent Form in C#.net Windows Applications


we know How to set the back color for the windows forms but MDI parent Not like that,because this is parent form to multiple child forms so that it follows different Specifications and Designs so we con't set the BackColor by statically,we do only  this by programatically show below how is.
 

above figure Normal MDI Parent without Color
code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Blogcode
{
    public partial class Mdicolor : Form
    {
        public Mdicolor()
        {
            InitializeComponent();
        }

        private void Mdicolor_Load(object sender, EventArgs e)
        {
            MdiClient chld;

            foreach (Control ctrl in this.Controls)
            {
                try
                {
                    chld = (MdiClient)ctrl;

                    chld.BackColor = this.BackColor;
                }

                catch (InvalidCastException exe)

                {

                }
            }
        }
    }
}



above figure Normal MDI Parent Form with Color

I hope this code will help you