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 to Create Array of Labels on the Run-Time ?

How to Create Array of Labels on the Run-Time ?

Scheduled Pinned Locked Moved Managed C++/CLI
data-structurestutorialquestion
9 Posts 2 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 Offline
    D Offline
    dataminers
    wrote on last edited by
    #1

    How to Create Array of Labels on the Run-Time ? Best Regards...

    2 1 Reply Last reply
    0
    • D dataminers

      How to Create Array of Labels on the Run-Time ? Best Regards...

      2 Offline
      2 Offline
      2bee
      wrote on last edited by
      #2

      Hello, if you mean with "Label" a System::Windows::Forms::Label control then you could use this snippet: // an array of 10 Labels array myLabelArray = gcnew array(10); regards Tobias

      D 1 Reply Last reply
      0
      • 2 2bee

        Hello, if you mean with "Label" a System::Windows::Forms::Label control then you could use this snippet: // an array of 10 Labels array myLabelArray = gcnew array(10); regards Tobias

        D Offline
        D Offline
        dataminers
        wrote on last edited by
        #3

        I try but error occur error C3149: 'cli::array' : cannot use this type here without a top-level '^'

        2 1 Reply Last reply
        0
        • D dataminers

          I try but error occur error C3149: 'cli::array' : cannot use this type here without a top-level '^'

          2 Offline
          2 Offline
          2bee
          wrote on last edited by
          #4

          Sorry my fault, my thoughts were faster than my fingers: (I forgot the '^' hat operator which classifies myLabelArray as a reference type) array^ myLabelArray = gcnew array(10); Tobias

          D 1 Reply Last reply
          0
          • 2 2bee

            Sorry my fault, my thoughts were faster than my fingers: (I forgot the '^' hat operator which classifies myLabelArray as a reference type) array^ myLabelArray = gcnew array(10); Tobias

            D Offline
            D Offline
            dataminers
            wrote on last edited by
            #5

            Thanks your help. array^ myLabelArray = gcnew array(10); //Its work But myLabelArray[0]->Location = Point(100,100); //NOT WORK :confused:

            2 1 Reply Last reply
            0
            • D dataminers

              Thanks your help. array^ myLabelArray = gcnew array(10); //Its work But myLabelArray[0]->Location = Point(100,100); //NOT WORK :confused:

              2 Offline
              2 Offline
              2bee
              wrote on last edited by
              #6

              Hi, maybe my first statement lead you in the wrong direction. array^ myLabelArray = gcnew array(10); This line just creates an array with 10 references of the type Label. A reference type is implicitly initialized with a nullptr, thus myLabelArray[0]->Location = Point(100,100); will not work unless you initialize it first. // will work lab[0] = gcnew Label(); lab[0]->Location = Point(10,10); You should also use try-catch to catch exceptions that possibly occur. regards Tobias

              D 1 Reply Last reply
              0
              • 2 2bee

                Hi, maybe my first statement lead you in the wrong direction. array^ myLabelArray = gcnew array(10); This line just creates an array with 10 references of the type Label. A reference type is implicitly initialized with a nullptr, thus myLabelArray[0]->Location = Point(100,100); will not work unless you initialize it first. // will work lab[0] = gcnew Label(); lab[0]->Location = Point(10,10); You should also use try-catch to catch exceptions that possibly occur. regards Tobias

                D Offline
                D Offline
                dataminers
                wrote on last edited by
                #7

                No Error Occur But I Can't See Label on the Form array^ myLabelArray = gcnew array(10); myLabelArray[0] = gcnew Label(); myLabelArray[0]->AutoSize = true; myLabelArray[0]->Location = System::Drawing::Point(100, 10); myLabelArray[0]->Name = L"lblX"; myLabelArray[0]->Size = System::Drawing::Size(63, 13); myLabelArray[0]->Text = "HELLO"; myLabelArray[0]->TabIndex = 50; myLabelArray[0]->Visible = true; :sigh: Best Regards

                2 1 Reply Last reply
                0
                • D dataminers

                  No Error Occur But I Can't See Label on the Form array^ myLabelArray = gcnew array(10); myLabelArray[0] = gcnew Label(); myLabelArray[0]->AutoSize = true; myLabelArray[0]->Location = System::Drawing::Point(100, 10); myLabelArray[0]->Name = L"lblX"; myLabelArray[0]->Size = System::Drawing::Size(63, 13); myLabelArray[0]->Text = "HELLO"; myLabelArray[0]->TabIndex = 50; myLabelArray[0]->Visible = true; :sigh: Best Regards

                  2 Offline
                  2 Offline
                  2bee
                  wrote on last edited by
                  #8

                  Hi, you forgot to add the label to the form. private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { array^ myLabelArray = gcnew array(10); myLabelArray[0] = gcnew Label(); myLabelArray[0]->AutoSize = true; myLabelArray[0]->Location = System::Drawing::Point(100, 10); myLabelArray[0]->Name = L"lblX"; myLabelArray[0]->Size = System::Drawing::Size(63, 13); myLabelArray[0]->Text = "HELLO"; myLabelArray[0]->TabIndex = 50; myLabelArray[0]->Visible = true; this->Controls->Add(myLabelArray[0]); } }; regards Tobias

                  D 1 Reply Last reply
                  0
                  • 2 2bee

                    Hi, you forgot to add the label to the form. private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { array^ myLabelArray = gcnew array(10); myLabelArray[0] = gcnew Label(); myLabelArray[0]->AutoSize = true; myLabelArray[0]->Location = System::Drawing::Point(100, 10); myLabelArray[0]->Name = L"lblX"; myLabelArray[0]->Size = System::Drawing::Size(63, 13); myLabelArray[0]->Text = "HELLO"; myLabelArray[0]->TabIndex = 50; myLabelArray[0]->Visible = true; this->Controls->Add(myLabelArray[0]); } }; regards Tobias

                    D Offline
                    D Offline
                    dataminers
                    wrote on last edited by
                    #9

                    It's work, thanks a lot 2bee... :-D

                    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