Custom form background color
Winforms by default don’t offer much customization as far as coloring, especially when it comes down to gradient patterns.
If you want to change the background of your form to something a bit more unique to make it look like this
First handle the form’s
private void Form1_Paint(object sender, PaintEventArgs e)
Graphics g = e.Graphics;
Rectangle rect = new Rectangle(0, 0, this.Size.Width, this.Size.Height);
LinearGradientBrush brush = new LinearGradientBrush(rect, Color.Green, Color.White, LinearGradientMode.ForwardDiagonal);
Feel free to change the colors and the gradient direction to what you would like.
Then we need to make sure that our form is properly painted when the user resizes the form. In order to do that we will need to handle the form#s
Resize event and Invalidate our form when it gets resized.
private void Form1_Resize(object sender, EventArgs e)
You will notice than when you resize the form some flickering happens. In order to eliminate that make sure to set your form’s
DoubleBuffered to true either by simply changing the property in the property window or by calling
this.DoubleBuffered = true; in your form’s constructor or in the