Problems in converting colors

Hi!

I'm using the colorDialog to let the user select a color, then I save it to the registry. Everything is fine except with the user doesn't select a named color. What I am getting save to the registry is something like:

ffff8000

I tried the following:

ColorConverter colConvert = new ColorConverter();

treeview1.ForeColor = (Color)colConvert.ConvertFromString(regkey.GetValue("ColorName").ToString());

But it's not working when the color is not named, e.g. Yellow.

I'm getting:

ffff8000 is not a valid value for Int32.

Please help. Thanks.



Answer this question

Problems in converting colors

  • sturdy

    you're getting a hex value, so you need to convert hex to decimal.

    int decCol = int.Parse(colorString, System.Globalization.NumberStyles.HexNumber);



  • Joyjit

    Hi,
    this page should answer your question:
    http://support.microsoft.com/Default.aspx kbid=835454

    If not, ask again that I'll try to help ;)


  • Problems in converting colors