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.
-
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.
LOL - just answered you on MSDN. int decAgain = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber); Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
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.
Hi, There's nothing wrong with the code that you have posted. Just only a misunderstanding of what ColorConverter does. ColorConverter, as you probably have guessed, is only meant to convert a named color, as defined by a constant of Color, to it's Color instance equalivalent. To convert the hex representation you can use
Color.FromArgb()
Post back if there's anything you don't understand. :) Graham. -
Hi, There's nothing wrong with the code that you have posted. Just only a misunderstanding of what ColorConverter does. ColorConverter, as you probably have guessed, is only meant to convert a named color, as defined by a constant of Color, to it's Color instance equalivalent. To convert the hex representation you can use
Color.FromArgb()
Post back if there's anything you don't understand. :) Graham.Just adding on to what Christian has answered: This should work. (I hope!)
Color c=Color.FromArgb(int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber));
[Edit] Yay! It works! :-D -- modified at 18:57 Sunday 18th June, 2006
-
Hi, There's nothing wrong with the code that you have posted. Just only a misunderstanding of what ColorConverter does. ColorConverter, as you probably have guessed, is only meant to convert a named color, as defined by a constant of Color, to it's Color instance equalivalent. To convert the hex representation you can use
Color.FromArgb()
Post back if there's anything you don't understand. :) Graham.