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. Visual Basic
  4. How can I call properties a run time created button?

How can I call properties a run time created button?

Scheduled Pinned Locked Moved Visual Basic
6 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.
  • J Offline
    J Offline
    JUNEYT
    wrote on last edited by
    #1

    Hello! It is quite bit intrique because I am creating 80 buttons in runtime and assigning a name with an incremental value such as myButton.Name = "GButton_" + I.toString. Therefore, each button has a different name.

    Dim I as Int32
        For I = 1 to 5
            Dim myButton as New Button
                myButton.Name = "GButton_" + I.toString
                me.controls.add(myButton)
        Next 
    

    How can I reach the GButton_3.backcolor property somewhere in code (out of the procedure where I create the buttons). Would it be possible to define the name and set its property? Is there a way to use such as EVAL function to perform something eval( "GButton_" + I.tostring + ".backcolor=" + setcolor) THANK YOU. :doh:

    What a curious mind needs to discover knowledge is noting else than a pin-hole.

    G T 2 Replies Last reply
    0
    • J JUNEYT

      Hello! It is quite bit intrique because I am creating 80 buttons in runtime and assigning a name with an incremental value such as myButton.Name = "GButton_" + I.toString. Therefore, each button has a different name.

      Dim I as Int32
          For I = 1 to 5
              Dim myButton as New Button
                  myButton.Name = "GButton_" + I.toString
                  me.controls.add(myButton)
          Next 
      

      How can I reach the GButton_3.backcolor property somewhere in code (out of the procedure where I create the buttons). Would it be possible to define the name and set its property? Is there a way to use such as EVAL function to perform something eval( "GButton_" + I.tostring + ".backcolor=" + setcolor) THANK YOU. :doh:

      What a curious mind needs to discover knowledge is noting else than a pin-hole.

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Why throw away the reference to the button that you actually have, and then try to get it again? Just store the references in an array so that you easily can access the buttons later.

      --- single minded; short sighted; long gone;

      1 Reply Last reply
      0
      • J JUNEYT

        Hello! It is quite bit intrique because I am creating 80 buttons in runtime and assigning a name with an incremental value such as myButton.Name = "GButton_" + I.toString. Therefore, each button has a different name.

        Dim I as Int32
            For I = 1 to 5
                Dim myButton as New Button
                    myButton.Name = "GButton_" + I.toString
                    me.controls.add(myButton)
            Next 
        

        How can I reach the GButton_3.backcolor property somewhere in code (out of the procedure where I create the buttons). Would it be possible to define the name and set its property? Is there a way to use such as EVAL function to perform something eval( "GButton_" + I.tostring + ".backcolor=" + setcolor) THANK YOU. :doh:

        What a curious mind needs to discover knowledge is noting else than a pin-hole.

        T Offline
        T Offline
        testy_proconsul
        wrote on last edited by
        #3

        hi, it is easier as you think either you iterate the "Controls" collection of the Form: For Each ctl as Control In Me.Controls If ctl.Name = "GButton2" Then ctl.Backcolor .... Exit For End If Next or you just call the following: Me.Controls("GButton2").Basckcolor ... storing it in an array is not necessary, because the added controls are already stored in an collection (Me.Controls)

        solidIT.de - under construction Components for Microsoft .Net audittrail, objectcomparer, deepcopy and much more ...

        J G 2 Replies Last reply
        0
        • T testy_proconsul

          hi, it is easier as you think either you iterate the "Controls" collection of the Form: For Each ctl as Control In Me.Controls If ctl.Name = "GButton2" Then ctl.Backcolor .... Exit For End If Next or you just call the following: Me.Controls("GButton2").Basckcolor ... storing it in an array is not necessary, because the added controls are already stored in an collection (Me.Controls)

          solidIT.de - under construction Components for Microsoft .Net audittrail, objectcomparer, deepcopy and much more ...

          J Offline
          J Offline
          JUNEYT
          wrote on last edited by
          #4

          Thank you! I will try it... :cool: :rose:

          What a curious mind needs to discover knowledge is noting else than a pin-hole.

          1 Reply Last reply
          0
          • T testy_proconsul

            hi, it is easier as you think either you iterate the "Controls" collection of the Form: For Each ctl as Control In Me.Controls If ctl.Name = "GButton2" Then ctl.Backcolor .... Exit For End If Next or you just call the following: Me.Controls("GButton2").Basckcolor ... storing it in an array is not necessary, because the added controls are already stored in an collection (Me.Controls)

            solidIT.de - under construction Components for Microsoft .Net audittrail, objectcomparer, deepcopy and much more ...

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            testy_proconsul wrote:

            it is easier as you think

            It's even easier than you think. ;)

            testy_proconsul wrote:

            storing it in an array is not necessary, because the added controls are already stored in an collection (Me.Controls)

            Yes, of course it's not necessary, but it's the easiest and fastest way to get the reference.

            --- single minded; short sighted; long gone;

            T 1 Reply Last reply
            0
            • G Guffa

              testy_proconsul wrote:

              it is easier as you think

              It's even easier than you think. ;)

              testy_proconsul wrote:

              storing it in an array is not necessary, because the added controls are already stored in an collection (Me.Controls)

              Yes, of course it's not necessary, but it's the easiest and fastest way to get the reference.

              --- single minded; short sighted; long gone;

              T Offline
              T Offline
              testy_proconsul
              wrote on last edited by
              #6

              "i dont wanted to cut you short" ... guffa. and sorry for my bad english :) but opinion is to keep the overhead as small as possible and to use predefined functionality. generally this keeps overview, readability and conformity ...

              solidIT.de - under construction Components for Microsoft .Net audittrail, objectcomparer, deepcopy and much more ...

              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