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. component property

component property

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

    Hi, how I can acces properties of component I created: I create 2 label in my form1, and later I want to get text from each of those labels I think it should look like this foreach(Label l in Form1.label) { console.write(l.text); } but I`m wrong...

    A 1 Reply Last reply
    0
    • V valiovalio

      Hi, how I can acces properties of component I created: I create 2 label in my form1, and later I want to get text from each of those labels I think it should look like this foreach(Label l in Form1.label) { console.write(l.text); } but I`m wrong...

      A Offline
      A Offline
      alexey N
      wrote on last edited by
      #2

      Try this code:foreach(Control ctrl in form1.Controls) { if (ctrl is Label) { console.write(((Label)ctrl).Text); } }
      Best regards, Alexey.

      V 1 Reply Last reply
      0
      • A alexey N

        Try this code:foreach(Control ctrl in form1.Controls) { if (ctrl is Label) { console.write(((Label)ctrl).Text); } }
        Best regards, Alexey.

        V Offline
        V Offline
        valiovalio
        wrote on last edited by
        #3

        First of all thank you for your answer, but I get this error An object reference is required for the nonstatic field, method, or property 'System.Windows.Forms.Control.Controls.get'

        V 1 Reply Last reply
        0
        • V valiovalio

          First of all thank you for your answer, but I get this error An object reference is required for the nonstatic field, method, or property 'System.Windows.Forms.Control.Controls.get'

          V Offline
          V Offline
          valiovalio
          wrote on last edited by
          #4

          Sorry everything is now working:) thank you very much

          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