Hi all,

How can I change the BACKGROUND color of the MDI FORM in C#?

I changed it using the background color property but the color is not changed.

What should I do to perform this task?

Please help me out!!

Thanks in advance!!

You can't for sorry change it!

It always defaults to the default background color of a control.

commented: Always comes to support.. +7

i tried something like this but it didnt work :

protected override void OnPaintBackground(PaintEventArgs e)
		{
			
			base.OnPaintBackground(e);
			Pen pen = new Pen(Color.Red, 3);
			Rectangle rect = new Rectangle(0, 0, 300, 300);
			e.Graphics.DrawRectangle(pen, rect);
			
		}
  1. Open your MDI form.
  2. From Properties, select the Background Color and change the color to your desired one.
  3. Generate MDI form_load event by double clicking the form.
  4. Paste the following code into form_load event.

        private void StartForm_Load(object sender, EventArgs e)
        {   
            MdiClient ctlMDI;
            foreach (Control ctl in this.Controls)
            {
                try
                {
                    ctlMDI = (MdiClient)ctl;
                    ctlMDI.BackColor = this.BackColor;
                }
                catch (InvalidCastException exc)
                {
                    // Catch and ignore the error if casting failed.
                }
            }
        }
    
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.