469,306 Members | 1,901 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

How to build Color Enum?

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
Aug 5 '07 #1
4 24499
"Rainer Queck" <Ra**********@nomail.nomail.comwrote in message
news:O5**************@TK2MSFTNGP03.phx.gbl...
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/lib...or.toargb.aspx

http://msdn2.microsoft.com/en-us/lib...rs(VS.80).aspx

http://msdn2.microsoft.com/en-us/lib...or(VS.80).aspx

Aug 5 '07 #2
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Rainer Queck" <Ra**********@nomail.nomail.comwrote in message
news:O5**************@TK2MSFTNGP03.phx.gbl...
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
Aug 5 '07 #3
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Rainer Queck" <Ra**********@nomail.nomail.comwrote in message
news:O5**************@TK2MSFTNGP03.phx.gbl...
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
Aug 5 '07 #4
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
Aug 6 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Imran | last post: by
4 posts views Thread by Nikhil Patel | last post: by
21 posts views Thread by Andreas Huber | last post: by
31 posts views Thread by Michael C | last post: by
1 post views Thread by ad | last post: by
5 posts views Thread by VJ | last post: by
reply views Thread by Ben Finney | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.