最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C# 實(shí)現(xiàn)顏色漸變窗體控件詳細(xì)講解

 更新時間:2021年01月14日 15:07:45   作者:牧羊君  
這篇文章主要介紹了C# 實(shí)現(xiàn)顏色漸變窗體控件詳細(xì)講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

1.建議設(shè)置窗體為雙緩沖繪圖,可有效避免界面刷時引起的閃爍

this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true); 

2、代碼實(shí)現(xiàn)

 private Color Color1 = Color.Gray; //起始顏色
 private Color Color2 = Color.White ; //目標(biāo)顏色
 private float changeAngle = 0f;    //漸變角度

3.窗體繪制函數(shù)

 private void Form1_Paint(object sender, PaintEventArgs e)
 {
      Graphics g = e.Graphics;
      Rectangle grounRect = new Rectangle(0, 0, this.Width, this.Height);
      System.Drawing.Drawing2D.LinearGradientBrush backGround = new System.Drawing.Drawing2D.LinearGradientBrush(grounRect, Color1, Color2, changeAngle);
      g.FillRectangle(backGround, grounRect);
      backGround.Dispose();
}

補(bǔ)充:WPS中 LinearGradientBrush線性漸變的使用

1、顏色列排列

注:

(1)列排列的起始坐標(biāo)為(0,0.5)終止坐標(biāo)為(1,0.5)

(2)其中offset放置的位置參數(shù)是需要計算的

​ 例如:一共四個顏色,那么就是1/4=0.25;表示一個顏色0.25,第一個顏色為0.25,第二個就是再加上0.25=0.5,第三個就是0.75,第四個就是1

public MainWindow()
    {
      InitializeComponent();
  //實(shí)例化一個Border控件,來設(shè)置這個背景線性漸變
      Border bord1 = new Border();
      bord1.Width = bord1.Height=200;
      indext.Children.Add(bord1);
  //線性漸變設(shè)置開始
      LinearGradientBrush brush = new LinearGradientBrush();//實(shí)例化線性漸變對象
  //列排列的起始坐標(biāo)為(0,0.5)終止坐標(biāo)為(1,0.5)
      brush.StartPoint = new Point(0, 0.5);//設(shè)置線性漸變的二維起始坐標(biāo)
      brush.EndPoint=new Point(1,0.5);//設(shè)置線性漸變的二維終止坐標(biāo)
      brush.GradientStops.Add(new GradientStop(color: Colors.Pink,offset:0.25));
  //GradientStops表示設(shè)置漸變的終止點(diǎn)
  //GradientStop第一個參數(shù)color是設(shè)置顏色,第二個參數(shù)offset是設(shè)置的位置
      brush.GradientStops.Add(new GradientStop(color: Colors.IndianRed,offset:0.50));
      brush.GradientStops.Add(new GradientStop(color: Colors.LightSteelBlue,offset:0.75));
      brush.GradientStops.Add(new GradientStop(color: Colors.LightSeaGreen,offset:1.0));
      bord1.Background = brush;
  //最后將設(shè)置好的漸變背景賦值給Border控件
    }

2、顏色行排列

注:

行排列的時候,起始位置和終止位置只是改變了位置

列排列的起始坐標(biāo)為(0.5,0)終止坐標(biāo)為(0.5,1)

public MainWindow()
    {
      InitializeComponent();
      Border bord1 = new Border();
      bord1.Width = bord1.Height=200;
      indext.Children.Add(bord1);
      LinearGradientBrush brush = new LinearGradientBrush();
   //顏色行排列位置改變
      brush.StartPoint = new Point(0.5,0);
      brush.EndPoint=new Point(0.5,1);
      brush.GradientStops.Add(new GradientStop(color: Colors.Pink,offset:0.25));
      brush.GradientStops.Add(new GradientStop(color: Colors.IndianRed,offset:0.50));
      brush.GradientStops.Add(new GradientStop(color: Colors.LightSteelBlue,offset:0.75));
      brush.GradientStops.Add(new GradientStop(color: Colors.LightSeaGreen,offset:1.0));
      bord1.Background = brush;
    }

3、左上角到右下角斜著排列

注:

如果說要斜著排列,那么它的起始位置和終止位置不用設(shè)置計算,默認(rèn)排列,只需要計算offset的位置大小

 public MainWindow()
    {
      InitializeComponent();
      Border bord1 = new Border();
      bord1.Width = bord1.Height=200;
      indext.Children.Add(bord1);
      LinearGradientBrush brush = new LinearGradientBrush();
      brush.GradientStops.Add(new GradientStop(color: Colors.Pink,offset:0.25));
      brush.GradientStops.Add(new GradientStop(color: Colors.IndianRed,offset:0.50));
      brush.GradientStops.Add(new GradientStop(color: Colors.LightSteelBlue,offset:0.75));
      brush.GradientStops.Add(new GradientStop(color: Colors.LightSeaGreen,offset:1.0));
      bord1.Background = brush;
    }

以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。

相關(guān)文章

最新評論

什邡市| 齐齐哈尔市| 军事| 安阳县| 乌苏市| 鲁甸县| 黄山市| 浏阳市| 乌恰县| 怀远县| 枞阳县| 丰镇市| 泸溪县| 新沂市| 西丰县| 穆棱市| 宣城市| 南开区| 沂水县| 临沧市| 沁水县| 太保市| 广安市| 宁远县| 长宁县| 莫力| 新营市| 丰镇市| 诸城市| 海盐县| 尉犁县| 海宁市| 喀喇| 响水县| 荃湾区| 长沙县| 台东县| 邳州市| 泰州市| 沙洋县| 洱源县|