开发者

Setting Color Using Number in C#

开发者 https://www.devze.com 2023-04-07 16:45 出处:网络
I can set a colors to object using Bru开发者_运维问答sh as follows: Brushes.Red How to apply the same using numbers,

I can set a colors to object using Bru开发者_运维问答sh as follows:

Brushes.Red

How to apply the same using numbers,

say,

SetColor("#ffffff");

The above is an imaginary example.


You can use ColorTranslator.FromHtml

EDIT - In response to your comment, you can create a brush based on your colour:

SolidBrush brush = new SolidBrush(ColorTranslator.FromHtml("#ffffff"));


You can make Brushes with your own Color:

Color col = Color.FromArgb(255, 255, 255);
SolidBrush br = new SolidBrush(col);

Hope that helps.


In WPF:

var x = (Color)ColorConverter.ConvertFromString("#faffff");


Color color = Color.FromRgb(255, 255, 255);

i assume you know how to calculate the values?


I think you are looking for the Color.FromArgb method. It has an overload that allows specifying the color as an integer number.


Color c = (Color)((new ColorConverter()).ConvertFromString("#ffffff"));
0

精彩评论

暂无评论...
验证码 换一张
取 消