Drawing a line with a gradient color

前端 未结 2 1655
慢半拍i
慢半拍i 2021-01-12 10:25

Is it possible to draw a line using a graduated colour?

I want to be able to draw a straight or a curved line (if possible) where at one end of the line is Blue and

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-12 11:19

    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));
            }
        }
    }
    

提交回复
热议问题