0

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!!

5
Contributors
4
Replies
6
Views
8 Years
Discussion Span
Last Post by six_sic6
0

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);
			
		}
0
  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.
                }
            }
        }
    
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.