Fill the Windows Form with Gradient color


how to fill the Windows Form with Gradient color

Using this function you can change the form backcolor to Gradient color.



private void PaintGradientColor(Color color1, Color color2, System.Drawing.Drawing2D.LinearGradientMode mode)
{
System.Drawing.Drawing2D.LinearGradientBrush a = new System.Drawing.Drawing2D.LinearGradientBrush(new RectangleF(0, 0, this.Width, this.Height), color1, color2, mode);
Graphics frmGraphics = this.CreateGraphics();
frmGraphics.FillRectangle(a, new RectangleF(0, 0, this.Width, this.Height));
frmGraphics.Dispose();
}




use this funcion inside Form_paint


private void Form1_Paint(object sender, PaintEventArgs e)
{
PaintGradientColor(Color.Blue, Color.Firebrick, System.Drawing.Drawing2D.LinearGradientMode.Horizontal);

}


Comments

Guest Author: Silvio12 Mar 2012

Great !!! Thanks.



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: