473,383 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 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 26207
"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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.