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. C#
  4. how to handle a mass of lables in C#?

how to handle a mass of lables in C#?

Scheduled Pinned Locked Moved C#
csharphelptutorialquestion
7 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.
  • M Offline
    M Offline
    momer
    wrote on last edited by
    #1

    The problem is: I want to use a for control sentence to control 16 lables,each time I want to change one lable's Text property.Suppose the 16 lables are lable1,lable2,lable3,...,lable16. What does the code should look like?

    M H 2 Replies Last reply
    0
    • M momer

      The problem is: I want to use a for control sentence to control 16 lables,each time I want to change one lable's Text property.Suppose the 16 lables are lable1,lable2,lable3,...,lable16. What does the code should look like?

      M Offline
      M Offline
      MoustafaS
      wrote on last edited by
      #2

      hi momor that will be for (i=1;i<=16;i++) { myLabel.Text = "Label" + i + "/n"; } that would help

      M 1 Reply Last reply
      0
      • M momer

        The problem is: I want to use a for control sentence to control 16 lables,each time I want to change one lable's Text property.Suppose the 16 lables are lable1,lable2,lable3,...,lable16. What does the code should look like?

        H Offline
        H Offline
        hatim_ali
        wrote on last edited by
        #3

        for(int i=0; i < this.Controls.Count; i++) if(this.Controls[i].GetType() == typeof(System.Windows.Forms.Label)) MessageBox.Show (this.Controls[i].Name);

        M 1 Reply Last reply
        0
        • M MoustafaS

          hi momor that will be for (i=1;i<=16;i++) { myLabel.Text = "Label" + i + "/n"; } that would help

          M Offline
          M Offline
          momer
          wrote on last edited by
          #4

          Hi!Moustafa_, Thank you very much! But what I need is not to change one lable's Text property for 16 times,but to change 16 lable's Text properties.I want to realize it with a for loop,and change one lable's Text property in each loop.In this case,what should my code look like? Thank you again!

          1 Reply Last reply
          0
          • H hatim_ali

            for(int i=0; i < this.Controls.Count; i++) if(this.Controls[i].GetType() == typeof(System.Windows.Forms.Label)) MessageBox.Show (this.Controls[i].Name);

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

            Hi!hatim_ali, Thank you very much for your help! I think your code give me much idear to work out my trouble.;)

            M 1 Reply Last reply
            0
            • M momer

              Hi!hatim_ali, Thank you very much for your help! I think your code give me much idear to work out my trouble.;)

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

              Hi!hatim_ali, The lable I want to get within each for loop is specified.That is,within the first loop I want to get lable1,within the second loop I want to get lable2,within the third loop I want to get lable3,...,within the 16th loop I want to get lable16.And there are more than 16 lables in my C# project,so if I use your code I don't know which lable I will get.I think maybe use a array or a enum which contains the 16 specified lables,but I just do not know what the array or enum's type should be and what the code look like. I need your help!;)

              H 1 Reply Last reply
              0
              • M momer

                Hi!hatim_ali, The lable I want to get within each for loop is specified.That is,within the first loop I want to get lable1,within the second loop I want to get lable2,within the third loop I want to get lable3,...,within the 16th loop I want to get lable16.And there are more than 16 lables in my C# project,so if I use your code I don't know which lable I will get.I think maybe use a array or a enum which contains the 16 specified lables,but I just do not know what the array or enum's type should be and what the code look like. I need your help!;)

                H Offline
                H Offline
                hatim_ali
                wrote on last edited by
                #7

                hi.... Enums Members[^] Arrays in C#[^] best of luck...

                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