zoukankan      html  css  js  c++  java
  • 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),那么渐变的起始颜色,是从三分之一处开始的

    如下图

  • 相关阅读:
    网络七层参考模型(OSI)
    TCP/IP体系结构
    VC调用外部程序接口
    处事八条
    HFC网络
    sql server 2005中的分区函数用法(partition by 字段) 
    Java实现的几个常用排序算法详细解读
    Java中读取字符文件类FileReader
    如何在Java中进行图片剪裁
    从零开始构建HTML 5 Web页面
  • 原文地址:https://www.cnblogs.com/chucklu/p/6382025.html
Copyright © 2011-2022 走看看