Paperback said:
That's tha way...I found it!
private void Page_Load(object sender, System.EventArgs e)
{
lblMsg.Text = "Testando parâmetro de cores";
SetColor(lblMsg,"Red");
}
private void SetColor(Label lblTexto, string strColor)
{
lblTexto.ForeColor = System.Drawing.Color.FromName(strColor); //This
method is the way --FromName--
}
UGLYYYYYY
Seriously, doing this is less intuitive, and way more fragile than
passing color as a color type.
I (or any future developers) can now break your code by doing
SetColor(lblmsg, "BlaBlaBla")
How about
private void SetColor(Label label, Color color)
{
label.ForeColor = color;
}
....
SetColor(myLabel, Color.Red);
Then, the programmer will get strong typing, (cannot pass an invalid
color), intellisense support etc..
Color.FromName will also incur a performance hit as well because it will
have to parse your string and map it to a valid colour.
HTH
JB