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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Assiging name to label dynamic way ???

Assiging name to label dynamic way ???

Scheduled Pinned Locked Moved C#
questioncsharpxml
4 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.
  • S Offline
    S Offline
    sikandarhayat
    wrote on last edited by
    #1

    I made a Windows form in C# which contains 2 labels and 2 text fields the label name are saved in xml the xml fomat is

    and u know to change the name of label we write label01.Text=string1; label02.Text=string2; I do not want to use this. in case I have many labels then?? My question is there any other way so that i change its text (geting label01 from xml and its respective text).throug loping crateria. thanks in advance..... Sikandar

    sikandar

    C F 2 Replies Last reply
    0
    • S sikandarhayat

      I made a Windows form in C# which contains 2 labels and 2 text fields the label name are saved in xml the xml fomat is

      and u know to change the name of label we write label01.Text=string1; label02.Text=string2; I do not want to use this. in case I have many labels then?? My question is there any other way so that i change its text (geting label01 from xml and its respective text).throug loping crateria. thanks in advance..... Sikandar

      sikandar

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You can iterate over the controls collection looking for labels if you prefer, and if that works with the data you need to place into the labels. You could even iterate over the controls collection and create a new collection of only labels, but as soon as a label is added or removed, this would be wrong ( unless you made a private property that did this every time you wanted the labels collection ).

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      1 Reply Last reply
      0
      • S sikandarhayat

        I made a Windows form in C# which contains 2 labels and 2 text fields the label name are saved in xml the xml fomat is

        and u know to change the name of label we write label01.Text=string1; label02.Text=string2; I do not want to use this. in case I have many labels then?? My question is there any other way so that i change its text (geting label01 from xml and its respective text).throug loping crateria. thanks in advance..... Sikandar

        sikandar

        F Offline
        F Offline
        freshonlineMax
        wrote on last edited by
        #3

        Hello My friend! Your request was not in definite. May be below code can help you : int i=1; foreach (Control ctrl In this.Controls) { if (ctrl Is Label) { ctrl.Text = "Label" + i.ToString(); i++; } } please contact me if i couldn't help you.

        S 1 Reply Last reply
        0
        • F freshonlineMax

          Hello My friend! Your request was not in definite. May be below code can help you : int i=1; foreach (Control ctrl In this.Controls) { if (ctrl Is Label) { ctrl.Text = "Label" + i.ToString(); i++; } } please contact me if i couldn't help you.

          S Offline
          S Offline
          sikandarhayat
          wrote on last edited by
          #4

          done thanks

          sikandar

          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