Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Color Using Number in C#

I can set a colors to object using Brush as follows:

Brushes.Red

How to apply the same using numbers,

say,

SetColor("#ffffff");

The above is an imaginary example.

like image 795
Shamim Hafiz - MSFT Avatar asked Dec 16 '22 09:12

Shamim Hafiz - MSFT


2 Answers

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"));
like image 83
James Avatar answered Dec 31 '22 11:12

James


You can make Brushes with your own Color:

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

Hope that helps.

like image 30
Salazaar Avatar answered Dec 31 '22 09:12

Salazaar