Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-color diagonal gradient in winforms [duplicate]

I am trying to fill a rectangle with a multi-color diagonal gradient in winforms that looks like the following example: diagonal gradient I know this is a WPF example, but is it possible to get similar results in winforms?

like image 454
ChandlerPelhams Avatar asked Dec 06 '11 15:12

ChandlerPelhams


1 Answers

Here is a little example for you

void MainFormPaint(object sender, PaintEventArgs e)
{
  LinearGradientBrush br = new LinearGradientBrush(this.ClientRectangle, Color.Black, Color.Black, 0 , false);
  ColorBlend cb = new ColorBlend();
  cb.Positions = new[] {0, 1/6f, 2/6f, 3/6f, 4/6f, 5/6f, 1};
  cb.Colors = new[] {Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Indigo, Color.Violet};
  br.InterpolationColors= cb;
  // rotate
  br.RotateTransform(45);
  // paint
  e.Graphics.FillRectangle(br, this.ClientRectangle);
}

here is the result

enter image description here

hope this helps

like image 148
punker76 Avatar answered Sep 28 '22 12:09

punker76