WPF 顏色漸變


轉自:http://www.360doc.com/content/12/1024/14/7362094_243471690.shtml

LinearGradientBrush 類:使用線性漸變繪制區域。

LinearGradientBrush 使用線性漸變繪制區域。線性漸變沿直線定義漸變。該直線的終點由線性漸變的 StartPoint 和 EndPoint 屬性定義。LinearGradientBrush 畫筆沿此直線繪制其 GradientStops。默認的線性漸變是沿對角方向進行的。
1、默認情況下,線性漸變的  StartPoint 是被繪制區域的左上角 (0,0),其 EndPoint 是被繪制區域的右下角 (1,1)。所得漸變的顏色是沿着對角方向路徑插入的。
2、要創建 水平線性漸變,請將  LinearGradientBrush 的 StartPoint 和 EndPoint 分別改為 (0,0.5) 和 (1,0.5)。
3、要創建 垂直線性漸變,請將  LinearGradientBrush 的 StartPoint 和 EndPoint 分別改為 (0.5,0) 和 (0.5,1)。
 
<!-- 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>
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;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM