|
Rank: Advanced Member Groups: Member
Joined: 9/4/2007 Posts: 114
|
When the following code is executed, the resulting Value is set to "Black" instead of "lightgrey".
ui_eoColorPicker_BannerBG.Value = System.Drawing.Color.FromName(ClassName.BannerBGColor);
The "ClassName.BannerBGColor" contains the value "lightgrey" that was saved in the database using the following statement.
bannerBGColor = eoColorPicker_BannerBG.getValue(); bannerbgcolorname = eoColorPicker_BannerBG.getNearestColorName(bannerBGColor);
bannerbgcolorname is saved in the database and then retrieved later to set the page color and pre-set the color picker for that element.
Why is lightgrey not resolved correctly? Other colors, e.g.: "steelblue" are saved and set correctly.
Thanks, Duane
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
This is because .NET calls the color as "LightGrAy" and W3C calls the color as "LightGrEy". The color picker has to follow W3C standard. However when you pass that value to .NET Color.FromName, it would not recognize it. So it might be better for you to save the color in hex format in your db.
Thanks!
|
|
Rank: Advanced Member Groups: Member
Joined: 9/4/2007 Posts: 114
|
Hello,
Actually, the hex format would be preferable, but I need to use the saved value to re-set the color picker when the form is reloaded. I was under the impression that setting the value property of the ColorPicker required a System.Drawing.Color value, not a string/hex format. Maybe I misunderstood the requirements of that property setting.
How would I set the Value property using a hex value? Using this code produces the following error:
ui_eoColorPicker_BannerBG.Value = "#c0c0c0";
Cannot implicitly convert type 'string' to 'System.Drawing.Color'
Thanks
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, You won't be able to do that. The type is Color, not String, so you will need to convert it. The conversion code is quite simple:
Code: C#
WebColorConverter converter = new WebColorConverter();
Color color = converter.ConvertFrom("#c0c0c0");
I believe this class also can do named colors. Thanks
|
|
Rank: Advanced Member Groups: Member
Joined: 9/4/2007 Posts: 114
|
Hello, I was not able to get your code to work, but found the following to convert from a hex value and set the page element.BackColor and colorpicker.Value successfully.
Code: C#
using System.ComponentModel;
using System.Drawing;
Color BannerBGColor = (Color)TypeDescriptor.GetConverter(typeof(Color)).ConvertFromString(ClassName.BannerBGColor);
ui_eoColorPicker_BannerBG.Value = BannerBGColor;
ui_pnl_ElementName.BackColor = BannerBGColor;
Thanks.
|
|