Programatically Change Color Of An Element to Hexa Color Code

January 10, 2013 12:45 pm
Andri Kasta Marengga

Programatically Change Color Of An Element to Hexa Color Code

Changing color (ex: forecolor) of an element is actually easy. You only have to do this one line script


txtNotification.ForeColor = System.Drawing.Color.Red;

But the weakness of this way is you can’t specify your personal color. Solution to this matter is we have to define our custom color (either in css file or by code) first and then use that color.

C# way:


System.Drawing.Color merah = System.Drawing.ColorTranslator.FromHtml("#C00");

txtNotification.ForeColor =merah;

CSS way:


// define "merah" first on your css file

txtStatus.CssClass = merah;

, ,

No comments yet.

Leave a Reply