Create button control at runtime

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • WebNewsReader

    #1

    Create button control at runtime

    This one should be easy ;)
    How can I create a button control at runtime using one that is already
    created and adjust the properties ?

    Thanks in advance

  • lord.zoltar@gmail.com

    #2
    Re: Create button control at runtime


    WebNewsReader wrote:
    This one should be easy ;)
    How can I create a button control at runtime using one that is already
    created and adjust the properties ?
    >
    Thanks in advance
    So you want a clone of an existing button, then change one or two
    things?

    Well, just creating a new button is easy:

    Dim b as new system.windows. forms.form.Butt on

    I don't think buttons have a clone method, so you could make a
    ClonableButton by defining a new class tha inherits Button and
    implements ICloneable.
    Or just set the properties you want (for quick and dirty solution):
    b.property1 = oldButton.prope rty1
    b.property2 = oldButton.prope rty2
    ....

    Comment

    • WebNewsReader

      #3
      Re: Create button control at runtime

      ok, that fixes my needs
      but there is a way to create using an array ?

      <lord.zoltar@gm ail.comwrote in message
      news:1166199834 .451792.206550@ 73g2000cwn.goog legroups.com...
      >
      WebNewsReader wrote:
      >This one should be easy ;)
      >How can I create a button control at runtime using one that is already
      >created and adjust the properties ?
      >>
      >Thanks in advance
      >
      So you want a clone of an existing button, then change one or two
      things?
      >
      Well, just creating a new button is easy:
      >
      Dim b as new system.windows. forms.form.Butt on
      >
      I don't think buttons have a clone method, so you could make a
      ClonableButton by defining a new class tha inherits Button and
      implements ICloneable.
      Or just set the properties you want (for quick and dirty solution):
      b.property1 = oldButton.prope rty1
      b.property2 = oldButton.prope rty2
      ...
      >

      Comment

      • lord.zoltar@gmail.com

        #4
        Re: Create button control at runtime


        WebNewsReader wrote:
        ok, that fixes my needs
        but there is a way to create using an array ?
        So now you want an array filled with buttons, huh? Ok!

        You can try this:
        dim btnArray as new ArrayList(10) 'estimate the capacity you'll need. I
        guessed at "10".
        there are other structures you can use, such as a generic list.

        then you can add buttons like this:
        dim myButton as new Button
        btnArray.add(my Button)

        and loop through the array like this:
        for each btn as Button in btnArray
        ...
        'some code goes in here
        next

        Comment

        • Mythran

          #5
          Re: Create button control at runtime



          <lord.zoltar@gm ail.comwrote in message
          news:1166204534 .432004.69500@8 0g2000cwy.googl egroups.com...
          >
          WebNewsReader wrote:
          >ok, that fixes my needs
          >but there is a way to create using an array ?
          >
          So now you want an array filled with buttons, huh? Ok!
          >
          You can try this:
          dim btnArray as new ArrayList(10) 'estimate the capacity you'll need. I
          guessed at "10".
          there are other structures you can use, such as a generic list.
          >
          then you can add buttons like this:
          dim myButton as new Button
          btnArray.add(my Button)
          >
          and loop through the array like this:
          for each btn as Button in btnArray
          ...
          'some code goes in here
          next
          >
          Hmm, if the number of buttons are known at compile-time, or even at runtime
          prior to creating the buttons, I would use an array rather than arraylist.
          But if the total number of buttons are unknown until they are all created,
          then using an ArrayList or List would be the way to go (I'm unfamiliar with
          the List<generic class, so you may also want to look into this as it may
          be just as efficient as using a normal array, but I'm not sure)...



          HTH,
          Mythran


          Comment

          Working...