C# WinForm修改Panel邊框顏色

來源:互聯網
上載者:User
無法在屬性面版裡直接修改,可以在Paint事件裡重畫。private void panel1_Paint(object sender, PaintEventArgs e)
{
    ControlPaint.DrawBorder(e.Graphics,
                                this.panel1.ClientRectangle,
                                Color.LightSeaGreen,//7f9db9
                                1,
                                ButtonBorderStyle.Solid,
                                Color.LightSeaGreen,
                                1,
                                ButtonBorderStyle.Solid,
                                Color.LightSeaGreen,
                                1,
                                ButtonBorderStyle.Solid,
                                Color.LightSeaGreen,
                                1,
                                ButtonBorderStyle.Solid);
}

url:http://greatverve.cnblogs.com/archive/2011/07/21/panel-border-color.html
附:C# RGB與16進位色彩轉換方法

#region [顏色:16進位轉成RGB]
        /// <summary>
        /// [顏色:16進位轉成RGB]
        /// </summary>
        /// <param name="strColor">設定16進位顏色 [返回RGB]</param>
        /// <returns></returns>
        public static System.Drawing.Color colorHx16toRGB(string strHxColor)
        {
            try
            {
                if (strHxColor.Length == 0)
                {//如果為空白
                    return System.Drawing.Color.FromA#000000;//設為黑色
                }
                else
                {//轉換顏色
                    return System.Drawing.Color.FromArgb(System.Int32.Parse(strHxColor.Substring(1, 2), System.Globalization.NumberStyles.AllowHexSpecifier), System.Int32.Parse(strHxColor.Substring(3, 2), System.Globalization.NumberStyles.AllowHexSpecifier), System.Int32.Parse(strHxColor.Substring(5, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
                }
            }
            catch
            {//設為黑色
                return System.Drawing.Color.FromA#000000;
            }
        }
        #endregion

 


#region [顏色:RGB轉成16進位]
        /// <summary>
        /// [顏色:RGB轉成16進位]
        /// </summary>
        /// <param name="R">紅 int</param>
        /// <param name="G">綠 int</param>
        /// <param name="B">藍 int</param>
        /// <returns></returns>
        public static string colorRGBtoHx16(int R, int G, int B)
        {
            return System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(R, G, B));
        }
        #endregion

 

又:


private string ToHexColor(Color color)
        {
            string R = Convert.ToString(color.R, 16);
            if (R == "0")
                R = "00";
            string G = Convert.ToString(color.G, 16);
            if (G == "0")
                G = "00";
            string B = Convert.ToString(color.B, 16);
            if (B == "0")
                B = "00";
            string HexColor = "#" + R + G + B;
            return HexColor;
        }

 

    public string ForeColor

    {

        set

        {

             //value = #ab364f

            int r = Convert.ToInt32("0x" + value.Substring(1, 2),16);

            int g = Convert.ToInt32("0x" + value.Substring(3, 2),16);

            int b = Convert.ToInt32("0x" + value.Substring(5, 2),16);

            txtUrl.ForeColor = System.Drawing.Color.FromArgb(r,g,b);

        }

 }

利用遞增的數字返回迴圈漸層的顏色的js代碼

function gCL(i){ 
var f=parseInt((i%15)/5); 
i=i%15%5; 
switch(f){ 
case 0:return "#"+cS2(255-i*51)+cS2(i*51)+"00"; 
case 1:return "#00"+cS2(255-i*51)+cS2(i*51); 
case 2:return "#"+cS2(i*51)+"00"+cS2(255-i*51); 


function cS2(i) { 
var s=i.toString(16); 
return ("00"+s).substr(s.length); 
}

 

使用gCL就可以利用遞增的數字返回由紅到綠到藍的漸層顏色了。漸層效果如下,共15種顏色,迴圈漸層:

http://kingoa.net/WEBPROGRAM/JAVASCRIPT/2010/0326/14021.html

 

CSS顏色值的三種形式:名稱、RGB、十六進位

從理論上說,CSS可以處理的顏色數量大概是:16,777,216。夠用了吧。如何表現這些顏色呢,主要是通過三種形式:

1、名稱 如:blue

2、RGB 如:255,0,0

3、十六進位 如:#ff6600

如果我們要設定紅色,可以是下面的形式:

名稱:red

RGB:#ff0000

RGB:rgb(100%,0%,0%)

十六進位:#ff0000

十六進位:#f00

CSS有十七個預先確定的顏色,它們是:

aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, orange, purple, red, silver, teal, white, yellow.

(注意:transparent 透明 也是一個正確的值。)

rgb的三個值都是從0到255,0是最低級,255是最進階,這些值同樣可以是百分比。

十六進位三或六個數字長度前面帶上#字元,三個長度是六個的壓縮形式(短16進位),比如#00f是#0000ff的壓縮,#c30是#cc3300。三位元很好理解,像rgb,第一個是紅色,第二個是綠色,第三個藍色。但六位元可以實現更多的顏色控制。

由於web安全色只使用了00,33,66,99,cc,ff,所以我們可以使用短16進位顏色表示web安全色,0,3,6,9,c,f和長16進位可以使用的顏色數值是等價的,一共是6×6×6=216種。最初的電腦(8位電腦)上只能定義256種顏色,所以當時Windows和Macintosh運行於256色,在Netscape Navigator和Microsoft Internet Explorer上共有的顏色就被稱為Web安全色.如果顏色不在這216種顏色的範圍內,電腦就有可能在顯示顏色的時候產生抖動現象。(抖動就是由於作業系統為了儘可能的表現某種顏色,混合兩種顏色而產生的)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.