How to get name all colors from class Drawing::Color

I want to get all names colors from class System::Drawing::Color.
I searching in forums this and else in network but samples whose I find not work in Visual Studio C++ 2008. Problem is witch typeof -

if i use samples
 
Type colorType = typeof(System.Drawing.Color);

them i have problem witch typeof.

I writing:

1
2
System::Drawing::Color cl;
array<String^>^ type = System::Enum::GetNames(cl.GetType());


but if i run i have error - why?

Can you help me.
Last edited on
What library are you using? What error are you getting? What are you trying to do?
I use library (my program is console app):

1
2
3
4
5
6
7
#using <mscorlib.dll>
#using <System.Drawing.dll>

...
System::Drawing::Color cl;
array<String^>^ type = System::Enum::GetNames(cl.GetType());
...


If I delete line array<String^>^... program go to end without error.
I want to get all names of color in class Color, and print it to screan.

Program is ended error:



An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll
Additional information: Type provided must be an Enum.


Last edited on
... You ARE using C++, right? I've never seen the 'using' pre-processor directive before, nor have I ever seen syntax as is being used when declaring your 'type' variable. I suggest you wait until someone who knows this stuff comes on.
That is C++/CLI, not C++
:O ....
closed account (z05DSL3A)
Here is some ugly code to play with...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using namespace System;
using namespace System::Drawing;

int main(array<System::String ^> ^args)
{
    System::Array^ colorsArray = Enum::GetValues( KnownColor::typeid );
    array<KnownColor>^allColors = gcnew array<KnownColor>(colorsArray->Length);
    Array::Copy( colorsArray, allColors, colorsArray->Length );

    array<System::String ^>^allColorsNames = gcnew array<System::String ^>(colorsArray->Length);


     for ( int i = 0; i < allColors->Length; i++ )
    {		
        allColorsNames[ i ] = allColors[ i ].ToString();
        Console::WriteLine(allColorsNames[ i ]);
    }

    return 0;
}
Thanks.

I must make small modification and work good ;-):

1
2
3
4
5
6
7
8
9
10
11
12
13
System::Array^ colorsArray = Enum::GetValues( System::Drawing::KnownColor::typeid );
    array<System::Drawing::KnownColor>^allColors = gcnew array<System::Drawing::KnownColor>(colorsArray->Length);
    Array::Copy( colorsArray, allColors, colorsArray->Length );

    array<System::String ^>^allColorsNames = gcnew array<System::String ^>(colorsArray->Length);


     for ( int i = 0; i < allColors->Length; i++ )
    {		
        allColorsNames[ i ] = allColors[ i ].ToString();
        Console::WriteLine(allColorsNames[ i ]);
    }
	


Topic archived. No new replies allowed.