I'm building a WinForms application, and I'm using specific colors on most controls. I do that sometimes from the WinForms designer, and sometimes directly into my code.
I got a static class somewhere looking like that :
public static class MyColors
{
public static Color DarkGreen = Color.FromArgb(0, 70, 62);
...
public static Color Orange = Color.FromArgb(239, 132, 16);
}
I can use those colors in my code quite easily, but it's impossible to do from the designer, which raises this error :
MyColors.DarkGreen is not a valid value for Int32.
(I've tried to store the Int32 representation of those colors, but this fails with the same error)
The solution I'm using right now is to use the rgb color code in the designer, the MyColors class values in my code, and I'm doing changes using the replace all functionality of Visual Studio. This isn't a nice solution, but I haven't been able to find a better idea so far.
Any ideas ?
Note : I know about this question, which is slightly different from mine, as I'm not looking at changing the "KnownColors".
Select Personalization > Colors. In the list for Choose your mode, select Custom. In the list for Choose your default Windows mode, select Dark. In the list for Choose your default app mode, select Light or Dark.
Here's your quick reference to the colors and icons in the editor window's right-hand margin: Yellow: The line has been changed but not yet saved. Green: The line has been changed and saved. Orange: The line has been changed, saved, and the change undone. Little square dots in the middle of the margin: Break points.
On the menu bar, select Tools > Options. In the options list, select Environment > General. In the Color theme list, choose between the default Dark theme, the Blue theme, the Blue (Extra Contrast) theme, and the Light theme. Or, choose the Use system setting option to select the theme that Windows uses.
To get designer support for your additional color definitions, you probably need to create your own editors that extend or replace the Color
editor. Once you have defined these, you then would need to tell the designer which properties should use your editor by applying the Editor
attribute to the affected properties.
You may also be able to achieve some success by doing something similar with a TypeConverter
and the TypeConverterAttribute
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With