Add color options to System.Drawings.Color

asp.net, asp.net-4.5, c#, system.drawing, visual-studio-2012

Solution

This list is based on `System.Drawing.KnownColor` enum values. As enums cannot be extended and you cannot inherit from another enum, if you want to create list with more named colors to use in your own code you have to implement your own enum with those values added manually and with additional ones you wish to see there.

And, of course, along with `System.Drawing.KnownColor` enum there is a method in `Color` struct that is used to get the value of this named color - `Color.FromKnownColor`. I think you should also add extention method to `Color` struct that will do the same for your own enum, as `FromKnownColor` method does for `KnownColor` enum. And maybe you can even use `FromKnownColor` method in your own extension method to make it simplier for colors that already exist in this standard enum.

But if the only thing you want to do is to extend this one list in ASP.NET designer, you cannot do this with any changes in your own project or by changing options in VS. Maybe you can write an add-in to Visual Studio to do this, but that's the only way I see, if it's what you wanted to do.

EDIT: If inheriting the control is an option for you, maybe the best answer you can get is the one suggested by simplecoder, as described in his answer - creating your own control based on the old one with this new enum values binded to the property you want to use new colors for.

Problem

In visual studio, when creating controls in the markup(or in code-behind) you can specify colors in HEX format like this: "#FFFFFF", but you also can select from the list of preset colors like: White, Wheat, Window, etc. (See screenshot). Is it possible to extend that list and add additional colors?

Original source

Related problems