Gradient line drawing

Is it possible to draw a line using graded color?

I want to be able to draw a straight or curved line (if possible) where there is blue at one end of the line and red at the other end.

Further It may be necessary to have more than one gradient in the line, for example, a color coming from blue → green → red. I think this can only consist of a few gradient lines combined together.

+6
c # winforms gdi + gradient line
source share
2 answers
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics graphicsObject = e.Graphics; using (Brush aGradientBrush = new LinearGradientBrush(new Point(0, 0), new Point(50, 0), Color.Blue, Color.Red)) { using (Pen aGradientPen = new Pen(aGradientBrush)) { graphicsObject.DrawLine(aGradientPen, new Point(0, 10), new Point(100, 10)); } } } 
+9
source share

you will need to use System.Drawing.Drawing2D.LinearGradientBrush instead of System.Drawing.SolidBrush

Example:

 e.Graphics.DrawLine(new Pen(new System.Drawing.Drawing2D.LinearGradientBrush(... 
+3
source share

All Articles