System.Drawing.Drawing2D.LinearGradientBrush

https://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.lineargradientbrush(v=vs.110).aspx

 

横向渐变

LinearGradientBrush linGrBrush = new LinearGradientBrush(
      new Point(0, 10),
      new Point(200, 10),
      Color.FromArgb(255, 255, 0, 0),   // Opaque red
      Color.FromArgb(255, 0, 0, 255));  // Opaque blue

            Pen pen = new Pen(linGrBrush);

            //public void DrawLine(Pen pen, int x1, int y1, int x2, int y2);
            e.Graphics.DrawLine(pen, 0, 10, 200, 10);

            //public void FillEllipse(Brush brush, int x, int y, int width, int height);
            //x,y是矩形的左上角的点的坐标,然后是宽和高。在矩形内部画椭圆
            e.Graphics.FillEllipse(linGrBrush, 0, 30, 200, 100);

            //public void FillRectangle(Brush brush, int x, int y, int width, int height);
            e.Graphics.FillRectangle(linGrBrush, 0, 155, 500, 30);

 

 new Point(0, 10), new Point(200, 10),

 

new Point(0, 10),  new Point(100, 10),

 

 

纵向渐变

  LinearGradientBrush linGrBrush = new LinearGradientBrush(
      new Point(0, 0),
      new Point(0, 30),
      Color.FromArgb(255, 255, 0, 0),   // Opaque red
      Color.FromArgb(255, 0, 0, 255));  // Opaque blue

            Pen pen = new Pen(linGrBrush);

            //public void DrawLine(Pen pen, int x1, int y1, int x2, int y2);
            e.Graphics.DrawLine(pen, 100, 0, 100, 30);

            //public void FillEllipse(Brush brush, int x, int y, int width, int height);
            //x,y是矩形的左上角的点的坐标,然后是宽和高。在矩形内部画椭圆
            e.Graphics.FillEllipse(linGrBrush, 0, 60, 200, 120);

            //public void FillRectangle(Brush brush, int x, int y, int width, int height);
            e.Graphics.FillRectangle(linGrBrush, 0, 210, 500, 30);

 

 

 

需要注意的是,纵向的渐变,是从坐标0开始的,而不是图形的0开始

假如最后一个矩形,左上角坐标改为(0,190),那么渐变的起始颜色,是从三分之一处开始的

如下图

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值