用渐变色画一条线 [英] Drawing a line with a gradient color

查看:108
本文介绍了用渐变色画一条线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用渐变色画线?

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 the other end is Red.

进一步,每行可能需要一个以上的渐变,例如,颜色从蓝色->绿色->红色开始.我认为这可能只包含绘制在一起的多条渐变线.

Further There might be a need to have more than one gradient per-line e.g the colour going from Blue -> Green -> Red. I am thinking that this might just consist of multiple gradient lines drawn together.

推荐答案

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

这篇关于用渐变色画一条线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆