Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-color linear gradient in WinForms

Tags:

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

like image 554
brain_pusher Avatar asked Oct 19 '11 14:10

brain_pusher


People also ask

Can color gradient linear?

To create a linear gradient you must define at least two color stops. Color stops are the colors you want to render smooth transitions among. You can also set a starting point and a direction (or an angle) along with the gradient effect.

How do you change the gradient color of a storyboard?

There are many ways to create background gradients, below is just one simple approach: In a new Xcode iOS project, open Main. storyboard, from the Object Library drag a new View onto the View Controller. Set the View's top, bottom, left and right constraints to be zero and ensure 'Constrain to margins' is deselected.


1 Answers

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

like image 151
punker76 Avatar answered Sep 29 '22 21:09

punker76