How to build Color Enum?

  • Thread starter Thread starter Rainer Queck
  • Start date Start date
R

Rainer Queck

Hello NG,

I would like to define a Color Enum like:

public enum MyColorEnum
{
Color1 = Color.Red,
Color2 = Color.Gren,
....
}

Unfortunately this doesn't work.
Is it possible to do some thing like this, and if yes, how?

Thanks for help!

Regards
Rainer
 
Rainer Queck said:
Hello NG,

I would like to define a Color Enum like:

public enum MyColorEnum
{
Color1 = Color.Red,
Color2 = Color.Gren,
....
}

Unfortunately this doesn't work.
Is it possible to do some thing like this, and if yes, how?

Thanks for help!

Regards
Rainer

The problem is that a Color cannot be converted to an integral value.
You may find some help here:

http://msdn2.microsoft.com/en-us/library/system.drawing.color.toargb.aspx

http://msdn2.microsoft.com/en-us/library/system.drawing.color_members(VS.80).aspx

http://msdn2.microsoft.com/en-us/library/system.drawing.color(VS.80).aspx
 
Rainer,

Enumeration values can only use integral types as a base (int, long,
byte, etc, etc), not structures or classes (like the Color structure).

What you could do is create a static class, exposing static read-only
properties/fields which you would set in the static constructor. This would
give you a class with the same semantics as an enumeration.
 
Rainer,

Enumeration values can only use integral types as a base (int, long,
byte, etc, etc), not structures or classes (like the Color structure).

What you could do is create a static class, exposing static read-only
properties/fields which you would set in the static constructor. This would
give you a class with the same semantics as an enumeration.
 
Hello Nicholas,
Enumeration values can only use integral types as a base (int, long,
byte, etc, etc), not structures or classes (like the Color structure).
That is what I thought, but I was hoping for a workaround....
What you could do is create a static class, exposing static read-only
properties/fields which you would set in the static constructor. This
would
give you a class with the same semantics as an enumeration.
A workaround like this :-)
Thanks for the hint!

Regards
Rainer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top