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

C# WinForm實現(xiàn)窗體漸變色效果的方法步驟

 更新時間:2025年11月19日 09:38:27   作者:yue008  
本文介紹了在WinForm項目中實現(xiàn)漸變色的方法,通過使用Color類的FromArgb屬性,結(jié)合for循環(huán)修改顏色參數(shù),并利用Graphics類進行圖形繪制,文中給大家介紹了具體的實現(xiàn)步驟,需要的朋友可以參考下

在winform項目開發(fā)中,需要實現(xiàn)漸變色。本文就詳細介紹如何實現(xiàn)。效果如下:

實現(xiàn)方案

利用Color類中FromArgb屬性,通過for循環(huán),修改color顏色,并使用Graphics類繪制

知識點

Color

FromArgb:

public static System.Drawing.Color FromArgb (int red, int green, int blue);

參數(shù):

  • red :Int32 新Color的紅色分量值。 有效值為 0 到 255。
  • green Int32 新Color的綠色組件值。 有效值為 0 到 255。
  • blue Int32 新Color的藍色分量值。 有效值為 0 到 255。

返回

Color

Color color1 = new Color();
for(int i=0;i<=255;i++)
{
    color1.FromArgb(1,i,100);
}

SolidBrush

定義單色畫筆。 畫筆用于填充圖形形狀,如矩形、橢圓、扇形、多邊形和封閉路徑。 此類不能被繼承。
SolidBrush(Color) 初始化指定顏色的新 SolidBrush 對象。

Color color1 = new Color();
for(int i=0;i<=255;i++)
{
    color1.FromArgb(1,i,100);
    SolidBrush SBrush = new SolidBrush(color);//實例化一個單色畫筆類對象SBrush
}

Pen

定義用于繪制直線和曲線的對象。 此類不能被繼承。
Pen(Brush, Single): 用指定的 Pen 和 Color 屬性初始化 Width 類的新實例。
參數(shù)

  • brush :Brush.一個 Brush,決定此 Pen 的特征。
  • width :Single。新 Pen 的寬度。
Color color1 = new Color();
for(int i=0;i<=255;i++)
{
    color1.FromArgb(1,i,100);
    SolidBrush SBrush = new SolidBrush(color);//實例化一個單色畫筆類對象SBrush
    Pen pen = new Pen(SBrush, 1);//實例化一個用于繪制直線和曲線的對象pen
}

Graphics

封裝一個 GDI+ 繪圖圖面。 此類不能被繼承。

方法

DrawRectangle:繪制由坐標對、寬度和高度指定的矩形。
DrawRectangle(Pen, Int32, Int32, Int32, Int32):繪制由坐標對、寬度和高度指定的矩形。

參數(shù)

  • pen :Pen。確定矩形的顏色、寬度和樣式的 Pen。
  • x : Int32,要繪制的矩形左上角的 x 坐標。
  • y : Int32,要繪制的矩形左上角的 y 坐標。
  • width: Int32 ,要繪制的矩形的寬度。
  • height: Int32.要繪制的矩形的高度。

OnPaintBackground(PaintEventArgs)

Control.OnPaintBackground(PaintEventArgs) 方法
繪制控件的背景。

代碼展示

protected override void OnPaintBackground(PaintEventArgs e)
{
    int intLocation, intHeight;//定義兩個int型的變量intLocation、intHeight 
    intLocation = this.ClientRectangle.Location.Y;//為變量intLocation賦值
    intHeight = this.ClientRectangle.Height / 200;//為變量intHeight賦值
    for (int i =255; i >= 0; i--)
    {
        Color color = new Color();//定義一個Color類型的實例color
        //為實例color賦值
        color = Color.FromArgb(1, i, 100);
        SolidBrush SBrush = new SolidBrush(color);//實例化一個單色畫筆類對象SBrush
        Pen pen = new Pen(SBrush, 1);//實例化一個用于繪制直線和曲線的對象pen
        e.Graphics.DrawRectangle(pen, this.ClientRectangle.X, intLocation, this.Width, intLocation + intHeight);//繪制圖形
        intLocation = intLocation + intHeight;//重新為變量intLocation賦值
    }
}

到此這篇關(guān)于C# WinForm實現(xiàn)窗體漸變色效果的方法步驟的文章就介紹到這了,更多相關(guān)C# WinForm窗體漸變色內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

任丘市| 芦溪县| 金乡县| 霍林郭勒市| 永兴县| 闻喜县| 临城县| 密云县| 漾濞| 宿松县| 六盘水市| 霍邱县| 乐清市| 呼伦贝尔市| 安阳市| 富裕县| 沧源| 稷山县| 张掖市| 东丽区| 西和县| 周至县| 天台县| 镇巴县| 崇仁县| 哈密市| 宜阳县| 吴忠市| 化德县| 汉寿县| 朔州市| 胶州市| 景洪市| 宝山区| 井研县| 鸡泽县| 平和县| 仪陇县| 乌鲁木齐市| 广德县| 增城市|