How do I generate a System::Drawing::Color array?
-
From the error message, you are using C++/CLI, so what you want is: array ^Color1 = {Color::Black, Color::Brown, Color::Red}; (edited Feb 19 to ignore html tags) David Anton http://www.tangiblesoftwaresolutions.com C++ to C# Converter C++ to VB Converter C++ to Java Converter Instant C#: VB to C# converter Instant VB: C# to VB converter Instant C++: convert VB or C# to C++/CLI Java to VB & C# Converter: convert Java to VB or C# modified on Tuesday, February 19, 2008 10:31 AM
Ack! Good eye - I don't know how many times I read it and missed the "^" LOL Cheers, Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
I would expect this to work...
Color Color1[] = __gc new Color[3];
What about this?
Color Color1 __gc[]= new Color __gc[3];
BTW, this is SO much nicer in VC 2005+ (without the managed extensions) :) Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
From the error message, you are using C++/CLI, so what you want is: array ^Color1 = {Color::Black, Color::Brown, Color::Red}; (edited Feb 19 to ignore html tags) David Anton http://www.tangiblesoftwaresolutions.com C++ to C# Converter C++ to VB Converter C++ to Java Converter Instant C#: VB to C# converter Instant VB: C# to VB converter Instant C++: convert VB or C# to C++/CLI Java to VB & C# Converter: convert Java to VB or C# modified on Tuesday, February 19, 2008 10:31 AM
-
The code was mangled when posting (forgot to check "ignore html tags.."). It should be: array ^Color1 = {Color::Black, Color::Brown, Color::Red}; David Anton http://www.tangiblesoftwaresolutions.com C++ to C# Converter C++ to VB Converter C++ to Java Converter Instant C#: VB to C# converter Instant VB: C# to VB converter Instant C++: convert VB or C# to C++/CLI Java to VB & C# Converter: convert Java to VB or C#
-
Yeah you were trying to use managed extensions (old) syntax so I assumed you were using VS 2002/2003 .NET. Since you're not, use the new array syntax (no more __gc) as shown by David Anton.
array<Color> ^Color1 = gcnew array<Color>(3);
or
array<Color> ^Color1 = gcnew array<Color>{Color::Black, Color::Brown, Color::Red};
or
array<Color> ^Color1 = {Color::Black, Color::Brown, Color::Red};
Mark *edit* Fixed the parenthesis above :rolleyes:
Last modified: 3hrs 18mins after originally posted --
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Yeah you were trying to use managed extensions (old) syntax so I assumed you were using VS 2002/2003 .NET. Since you're not, use the new array syntax (no more __gc) as shown by David Anton.
array<Color> ^Color1 = gcnew array<Color>(3);
or
array<Color> ^Color1 = gcnew array<Color>{Color::Black, Color::Brown, Color::Red};
or
array<Color> ^Color1 = {Color::Black, Color::Brown, Color::Red};
Mark *edit* Fixed the parenthesis above :rolleyes:
Last modified: 3hrs 18mins after originally posted --
Mark Salsbery Microsoft MVP - Visual C++ :java:
Hi Mark, I tried each of your suggestions, which should, as far as I know, do the same and work, but each caused errors: array ^Color1 = gcnew array[3]; error C2726: 'gcnew' may only be used to create an object with managed type array ^Color1 = gcnew array{Color::Black, Color::Brown, Color::Red}; error C3145: 'Color1' : global or static variable may not have managed type 'cli::array ^' with [ Type=System::Drawing::Color ] may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap error C3145: '$S9' : global or static variable may not have managed type 'cli::array ^' with [ Type=System::Drawing::Color ] may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap array ^Color1 = {Color::Black, Color::Brown, Color::Red}; error C3145: 'Color1' : global or static variable may not have managed type 'cli::array ^' with [ Type=System::Drawing::Color ] may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap I really don't know why this doesn't work.
-
Hi Mark, I tried each of your suggestions, which should, as far as I know, do the same and work, but each caused errors: array ^Color1 = gcnew array[3]; error C2726: 'gcnew' may only be used to create an object with managed type array ^Color1 = gcnew array{Color::Black, Color::Brown, Color::Red}; error C3145: 'Color1' : global or static variable may not have managed type 'cli::array ^' with [ Type=System::Drawing::Color ] may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap error C3145: '$S9' : global or static variable may not have managed type 'cli::array ^' with [ Type=System::Drawing::Color ] may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap array ^Color1 = {Color::Black, Color::Brown, Color::Red}; error C3145: 'Color1' : global or static variable may not have managed type 'cli::array ^' with [ Type=System::Drawing::Color ] may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap I really don't know why this doesn't work.
hehe WTH? What version of Visual Studio are you using?? Are you compiling for clr? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
hehe WTH? What version of Visual Studio are you using?? Are you compiling for clr? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
This is managed code, so you must use the /clr compiler switch (Project settings/Configuration Properties/General/Common Language Runtime Support) Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Also, I fixed the code in my last post - maybe that will work better. Sorry about that :) Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: