How to create multi-color linear gradient in WinForms? System.Drawing.Drawing2D.LinearGradientBrush allows only two colors.
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.
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.
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
hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With