Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. How do I generate a System::Drawing::Color array?

How do I generate a System::Drawing::Color array?

Scheduled Pinned Locked Moved Managed C++/CLI
questionc++graphicsdata-structureshelp
13 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Dave Doknjas

    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

    M Offline
    M Offline
    Mark Salsbery
    wrote on last edited by
    #4

    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:

    1 Reply Last reply
    0
    • M Mark Salsbery

      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:

      M Offline
      M Offline
      Manfr3d
      wrote on last edited by
      #5

      Thanks but this also doesn't work, it just causes more errors.

      M 1 Reply Last reply
      0
      • D Dave Doknjas

        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

        M Offline
        M Offline
        Manfr3d
        wrote on last edited by
        #6

        Thanks but it doesn't work. :(

        D 1 Reply Last reply
        0
        • M Manfr3d

          Thanks but it doesn't work. :(

          D Offline
          D Offline
          Dave Doknjas
          wrote on last edited by
          #7

          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#

          1 Reply Last reply
          0
          • M Manfr3d

            Thanks but this also doesn't work, it just causes more errors.

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #8

            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:

            M 1 Reply Last reply
            0
            • M Mark Salsbery

              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:

              M Offline
              M Offline
              Manfr3d
              wrote on last edited by
              #9

              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.

              M 1 Reply Last reply
              0
              • M Manfr3d

                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.

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #10

                hehe WTH? What version of Visual Studio are you using??  Are you compiling for clr? Mark

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                M 1 Reply Last reply
                0
                • M Mark Salsbery

                  hehe WTH? What version of Visual Studio are you using??  Are you compiling for clr? Mark

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                  M Offline
                  M Offline
                  Manfr3d
                  wrote on last edited by
                  #11

                  Well, I'm using Visual C++ Express Edition 2008. What do you mean with compiling for clr?

                  M 2 Replies Last reply
                  0
                  • M Manfr3d

                    Well, I'm using Visual C++ Express Edition 2008. What do you mean with compiling for clr?

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #12

                    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:

                    1 Reply Last reply
                    0
                    • M Manfr3d

                      Well, I'm using Visual C++ Express Edition 2008. What do you mean with compiling for clr?

                      M Offline
                      M Offline
                      Mark Salsbery
                      wrote on last edited by
                      #13

                      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:

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups