Mikk
Mikk

Reputation: 455

How to change a control's text font color programmatically into a custom color

I have a button control. I'd like to change it's text's font color into a custom color that I want which is #33CCFF, programmatically.

My current code is

Button1.ForeColor = Color.#33CCFF;

I have also tried

Button1.ForeColor = #33CCFF;

Both didnt work..

What's the correct way of doing this?

Upvotes: 3

Views: 9372

Answers (3)

jAC
jAC

Reputation: 5325

You could use:

Button1.ForeColor = (Color)ColorConverter.ConvertFromString("#33CCFF");

For reference: ColorConverter on MSDN

Alternatively you can use ColorTranslator:

Button1.ForeColor = System.Drawing.ColorTranslator.FromHtml("#33CCFF");

Upvotes: 6

Wim Ombelets
Wim Ombelets

Reputation: 5265

Button1.BackColor = System.Drawing.ColorTranslator.FromHtml("#FFFF00");

where you can use an RGB hexadecimal code.

Upvotes: 0

Steve B
Steve B

Reputation: 37710

Button1.ForeColor = Color.FromArgb(0x0033CCFF);

Reference : Color.FromArgb Method

Upvotes: 0

Related Questions