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. Could I index controls?

Could I index controls?

Scheduled Pinned Locked Moved C#
csharpdatabasequestion
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.
  • B Offline
    B Offline
    blackhattrick
    wrote on last edited by
    #1

    This is a feature I've seen with the picture control on VB, but could I do that with text boxes or buttons on C#? I´m trying to change some properties of textboxes but I want to use iteration. For instance, I want to assign the for cycle counter's value to each textbox and display it. 1 for textbox1.text, 2 for textbox2.text and so on. If anybody has another method to do this please tell me. I hope made myself clear and excuse my english. Regards Ivan

    T L B 3 Replies Last reply
    0
    • B blackhattrick

      This is a feature I've seen with the picture control on VB, but could I do that with text boxes or buttons on C#? I´m trying to change some properties of textboxes but I want to use iteration. For instance, I want to assign the for cycle counter's value to each textbox and display it. 1 for textbox1.text, 2 for textbox2.text and so on. If anybody has another method to do this please tell me. I hope made myself clear and excuse my english. Regards Ivan

      T Offline
      T Offline
      teejayem
      wrote on last edited by
      #2

      You can create an array of pretty much any type (in your case text boxes). Note: Pseudo Code

      TextBox[] myTextBoxes = new TextBox[5]

      for(int index = 0; index < myTextBoxes.Length; index++)
      {
      myTextBoxes[index] = new TextBox();
      myTextBoxes[index].Text = String.Format("TextBox #{0}", index+1);
      }

      Don't be overcome by evil, but overcome evil with good

      1 Reply Last reply
      0
      • B blackhattrick

        This is a feature I've seen with the picture control on VB, but could I do that with text boxes or buttons on C#? I´m trying to change some properties of textboxes but I want to use iteration. For instance, I want to assign the for cycle counter's value to each textbox and display it. 1 for textbox1.text, 2 for textbox2.text and so on. If anybody has another method to do this please tell me. I hope made myself clear and excuse my english. Regards Ivan

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Additionally to what teejayem said: if you want to modify the textboxes of your form, then you can do this:

        foreach(Control c in this.Controls)
        {
        if(c is TextBox)
        ((TextBox)c).Text = insert_your_text_here;
        }

        regards

        1 Reply Last reply
        0
        • B blackhattrick

          This is a feature I've seen with the picture control on VB, but could I do that with text boxes or buttons on C#? I´m trying to change some properties of textboxes but I want to use iteration. For instance, I want to assign the for cycle counter's value to each textbox and display it. 1 for textbox1.text, 2 for textbox2.text and so on. If anybody has another method to do this please tell me. I hope made myself clear and excuse my english. Regards Ivan

          B Offline
          B Offline
          blackhattrick
          wrote on last edited by
          #4

          Thank you a lot, your aid was really helpful Ivan

          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