Change background color customize C#
i want to use the F1开发者_开发技巧EFE2 color in Window App form background.how to write the code in C#.
If you are intersted in System.Windows.Media.Color
you can use this snippet (make you sure you added System.Widnows.Media
namespace):
Color backGroundColor = (Color)ColorConverter.ConvertFromString("#F1EFE2");
If you are interested in System.Drawing.Color
you can use ColorConverter from System.Drawing
namespace:
ColorConverter cc = new ColorConverter();
Color backGroundColor = cc.ConvertFromString("#F1EFE2");
For asp.net in codebehind:
Form1.Attributes.Add("style", "background-color:#f1efe2");
side note: better to use class instead of style.
Ok winforms. First convert to rgb then do this:
this.BackColor = Color.FromArgb(241, 239, 226);
Here's a convertor: http://www.javascripter.net/faq/hextorgb.htm
i am assuming your form id is form1, now in style tag use this:
#form1{
background-color:#f1efe2;
}
FOR windows app use this:
Imports System.Windows.Media
Color bgcolor = (Color)ColorConverter.ConvertFromString("#f1efe2");
(this assumes an RGB value)
or
Color bgcolor = System.Drawing.ColorTranslator.FromHtml("#f1efe2");
Hope this helps.
精彩评论