zoukankan      html  css  js  c++  java
  • LinearGradientBrush和GradientStop类

    LinearGradientBrush指的是一个线性的坡度类,用它和GradientStop类可以为一个矩形区域填充渐变的颜色。

    例如:

    <!-- This rectangle is painted with a diagonal linear gradient. --> <Rectangle Width="200" Height="100"> <Rectangle.Fill> <LinearGradientBrush StartPoint="0,0" EndPoint="1,1"> <GradientStop Color="Yellow" Offset="0.0" /> <GradientStop Color="Red" Offset="0.25" /> <GradientStop Color="Blue" Offset="0.75" /> <GradientStop Color="LimeGreen" Offset="1.0" /> </LinearGradientBrush> </Rectangle.Fill> </Rectangle>注意,(0,0)指的是矩形的左上角,(1,1)指的是矩形的右下角。所以颜色的渐变效果如下:GradientStop.jpg对应的c#代码如下:
    Rectangle diagonalFillRectangle = new Rectangle();
    diagonalFillRectangle.Width = 200;
    diagonalFillRectangle.Height = 100;
    // Create a diagonal linear gradient with four stops.  
    LinearGradientBrush myLinearGradientBrush =
        new LinearGradientBrush();
    myLinearGradientBrush.StartPoint = new Point(0,0);
    myLinearGradientBrush.EndPoint = new Point(1,1);
    myLinearGradientBrush.GradientStops.Add(
        new GradientStop(Colors.Yellow, 0.0));
    myLinearGradientBrush.GradientStops.Add(
        new GradientStop(Colors.Red, 0.25));               
    myLinearGradientBrush.GradientStops.Add(
        new GradientStop(Colors.Blue, 0.75));       
    myLinearGradientBrush.GradientStops.Add(
        new GradientStop(Colors.LimeGreen, 1.0));
     
    // Use the brush to paint the rectangle.
    diagonalFillRectangle.Fill = myLinearGradientBrush;
    同理,如果要创建水平方向的颜色渐变,设置StartPoint为(0,0.5),EndPoint为(1,0.5),如果要创建竖直方向的颜色渐变,设置StartPoint为(0.5,0),EndPoint为(0.5,1)。

  • 相关阅读:
    db4o 7.4 for .net3.5试用手记
    ruby学习笔记(2)类的基本使用
    温故而知新:设计模式之适配器模式(Adapter)
    Silverlight:Dependency Property(依赖属性)学习笔记
    Silverlight中的帧
    关闭与恢复visual studio实时调试器
    温故而知新:设计模式之桥接模式(Bridge)
    温故而知新:设计模式之单件模式(Singleton)
    一段oracle中的“复杂”分组统计sql
    VisualTreeHelper
  • 原文地址:https://www.cnblogs.com/bear831204/p/1310206.html
Copyright © 2011-2022 走看看