Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How to create multi-color linear gradient in WinForms? System.Drawing.Drawing2D.LinearGradientBrush allows only two colors.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
350 views
Welcome To Ask or Share your Answers For Others

1 Answer

same answer as here: Multi-color diagonal gradient in winforms Multi-color diagonal gradient in winforms

Here is a little example

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...