472,804 Members | 787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,804 software developers and data experts.

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 25955
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Imran | last post by:
Hello All I have a enum decla like this enum Days // Declare enum type Days { saturday, // saturday = 0 by default sunday = 0, // sunday = 0 as well monday, ...
4
by: Nikhil Patel | last post by:
Hi all, I am a VB6 programmer and learning C#. I am currently reading a chapter on types. I have question regarding enums. Why do we need to convert enum members to the value that they represent?...
21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
31
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1();...
1
by: ad | last post by:
I cant to write a function to manage the font color of my web. The function is like: using System.Drawing; public static string Font(string input, Color my) { string sRV = ""; sRV = "<font...
5
by: VJ | last post by:
I have one VB.NET project, that outputs a "Mycomapny.exe" everytime I do a build. But I need it to output 4 different executables everytime I build. How do I archive this. I am looking at the...
13
by: Don | last post by:
How do I get an Enum's type using only the Enum name? e.g. Dim enumType as System.Type Dim enumName as String = "MyEnum" enumType = ???(enumName)
0
by: Ben Finney | last post by:
Howdy all, I've uploaded enum 0.3 to the Cheeseshop. <URL:http://cheeseshop.python.org/pypi/enum/> Enumerations are now sequences, iterable (as before) *and* indexable:: >>> from enum...
2
msjonathan
by: msjonathan | last post by:
Hi, I am making a program with multiple grids, the user can drag&drop rows between Grids. For visualizing this nice and easy I give each row in a grid an other color. For the moment I store the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.