33

How can I set a form's backcolor to a custom color (such as light pink) using C# code?

Otiel
  • 18,404
  • 16
  • 78
  • 126
jimmy
  • 353
  • 1
  • 4
  • 5

3 Answers3

95

If you want to set the form's back color to some arbitrary RGB value, you can do this:

this.BackColor = Color.FromArgb(255, 232, 232); // this should be pink-ish
MusiGenesis
  • 74,184
  • 40
  • 190
  • 334
  • 1
    @MusiGenesis It works fine for me too, but it says: "Virtual member call in constructor", what does it mean, should I do anything about it? :) – radbyx May 16 '12 at 10:54
  • 1
    @radbyx This is many moons later, but the answer to your question is here: http://stackoverflow.com/questions/119506/virtual-member-call-in-a-constructor. In summary, sealing your class will make the warning go away. – AJ X. Mar 04 '16 at 21:15
  • "using System.Drawing;" Preprocessor need to use – abdullah_bd May 04 '20 at 11:08
15

With Winforms you can use Form.BackColor to do this.
From within the Form's code:

BackColor = Color.LightPink;

If you mean a WPF Window you can use the Background property.
From within the Window's code:

Background = Brushes.LightPink;
Brian R. Bondy
  • 339,232
  • 124
  • 596
  • 636
0

Define BackGround Color ShowDialog

ColorDialog bgColor = new ColorDialog();

After if you want change the color according to selected color

bgColor.ShowDialog();
this.BackColor = bgColor.Color;
Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
Kadir GUR
  • 1
  • 1