Picturebox Array (VB Express)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • toby@mkkbb.f9.co.uk

    #1

    Picturebox Array (VB Express)

    Hi there,

    Is it possible to create an array of picturebox controls during
    run-time. I wish to create a new image/picturebox everytime a user
    clicks the button on a form, and they need to be objects so that the
    user can move/drag them around.


    The only examples I can find dont work as I am using VB Express (2005?)

    and the examples are writting in VB6.


    Is anyone able to help please?


    Toby.

  • Stephany Young

    #2
    Re: Picturebox Array (VB Express)

    At class level in your form:

    Private m_pictureboxes As New ArrayList()

    In the Click event handler of your button:

    Dim _pic As New PictureBox

    _pic.Location = New System.Drawing. Point(<x>, <y>)

    _pic.Size = New System.Drawing. Size(<w>, <h>)

    ' set any other properties as required

    ' wire up the desired event handlers
    AddHandler _pic.<event>, AddressOf <event_handle r>

    Me.Controls.Add (_pic)

    m_pictureboxes. Add(_pic)

    where:

    <xand <yare the coordinates of the desired iniial position
    <wand <hare the width and height values for the desired size
    <eventis the desired event
    <event_handleri s the desired event hander (predefined)

    e.g.

    Private Sub PictureBox_Clic k(ByVal sender As System.Object, ByVal e As
    System.EventArg s)

    CType(sender, PictureBox).Bac kColor = Color.CadetBlue

    End Sub

    If you 'add' 3 pictureboxes by clicking the button three times and then
    click a picturebox, it's background colour will change.

    Obviously you will have to implement a mechanism for varying the <xand <y>
    values otherwise all the pictureboxes will be drawn in the same place.


    <toby@mkkbb.f9. co.ukwrote in message
    news:1167871978 .970527.168530@ 31g2000cwt.goog legroups.com...
    Hi there,
    >
    Is it possible to create an array of picturebox controls during
    run-time. I wish to create a new image/picturebox everytime a user
    clicks the button on a form, and they need to be objects so that the
    user can move/drag them around.
    >
    >
    The only examples I can find dont work as I am using VB Express (2005?)
    >
    and the examples are writting in VB6.
    >
    >
    Is anyone able to help please?
    >
    >
    Toby.
    >

    Comment

    • Cor Ligthert [MVP]

      #3
      Re: Picturebox Array (VB Express)

      Toby,

      Instead of the label1 and label2 you can use pictureboxes



      Cor


      <toby@mkkbb.f9. co.ukschreef in bericht
      news:1167871978 .970527.168530@ 31g2000cwt.goog legroups.com...
      Hi there,
      >
      Is it possible to create an array of picturebox controls during
      run-time. I wish to create a new image/picturebox everytime a user
      clicks the button on a form, and they need to be objects so that the
      user can move/drag them around.
      >
      >
      The only examples I can find dont work as I am using VB Express (2005?)
      >
      and the examples are writting in VB6.
      >
      >
      Is anyone able to help please?
      >
      >
      Toby.
      >

      Comment

      • toby@mkkbb.f9.co.uk

        #4
        Re: Picturebox Array (VB Express)

        Thanks very much for the responses, looks like I was almost there, but
        your examples have been a godsend! :-)

        Thanks again.

        Comment

        • toby@mkkbb.f9.co.uk

          #5
          Re: Picturebox Array (VB Express)


          Stephany Young wrote:
          At class level in your form:
          >
          Private m_pictureboxes As New ArrayList()
          >
          In the Click event handler of your button:
          >
          Dim _pic As New PictureBox
          >
          _pic.Location = New System.Drawing. Point(<x>, <y>)
          >
          _pic.Size = New System.Drawing. Size(<w>, <h>)
          >
          ' set any other properties as required
          >
          ' wire up the desired event handlers
          AddHandler _pic.<event>, AddressOf <event_handle r>
          >
          Me.Controls.Add (_pic)
          >
          m_pictureboxes. Add(_pic)
          >
          where:
          >
          <xand <yare the coordinates of the desired iniial position
          <wand <hare the width and height values for the desired size
          <eventis the desired event
          <event_handleri s the desired event hander (predefined)
          >
          e.g.
          >
          Private Sub PictureBox_Clic k(ByVal sender As System.Object, ByVal e As
          System.EventArg s)
          >
          CType(sender, PictureBox).Bac kColor = Color.CadetBlue
          >
          End Sub
          >
          If you 'add' 3 pictureboxes by clicking the button three times and then
          click a picturebox, it's background colour will change.
          >
          Obviously you will have to implement a mechanism for varying the <xand <y>
          values otherwise all the pictureboxes will be drawn in the same place.
          >
          >
          <toby@mkkbb.f9. co.ukwrote in message
          news:1167871978 .970527.168530@ 31g2000cwt.goog legroups.com...
          Hi there,

          Is it possible to create an array of picturebox controls during
          run-time. I wish to create a new image/picturebox everytime a user
          clicks the button on a form, and they need to be objects so that the
          user can move/drag them around.


          The only examples I can find dont work as I am using VB Express (2005?)

          and the examples are writting in VB6.


          Is anyone able to help please?


          Toby.
          Stepahnie,

          How can I reference the image property of a picturebox in an array. I
          would ahve assumed it was:

          m_picturebox(1) .image

          but that brings up errors. How can I change properties of these
          controls in the array?

          Thanks.

          Comment

          • Stephany Young

            #6
            Re: Picturebox Array (VB Express)

            What 'errors'?


            <toby@mkkbb.f9. co.ukwrote in message
            news:1167915170 .633333.76740@i 80g2000cwc.goog legroups.com...
            >
            Stephany Young wrote:
            >At class level in your form:
            >>
            > Private m_pictureboxes As New ArrayList()
            >>
            >In the Click event handler of your button:
            >>
            > Dim _pic As New PictureBox
            >>
            > _pic.Location = New System.Drawing. Point(<x>, <y>)
            >>
            > _pic.Size = New System.Drawing. Size(<w>, <h>)
            >>
            > ' set any other properties as required
            >>
            > ' wire up the desired event handlers
            > AddHandler _pic.<event>, AddressOf <event_handle r>
            >>
            > Me.Controls.Add (_pic)
            >>
            > m_pictureboxes. Add(_pic)
            >>
            >where:
            >>
            > <xand <yare the coordinates of the desired iniial position
            > <wand <hare the width and height values for the desired size
            > <eventis the desired event
            > <event_handleri s the desired event hander (predefined)
            >>
            >e.g.
            >>
            > Private Sub PictureBox_Clic k(ByVal sender As System.Object, ByVal e As
            >System.EventAr gs)
            >>
            > CType(sender, PictureBox).Bac kColor = Color.CadetBlue
            >>
            > End Sub
            >>
            >If you 'add' 3 pictureboxes by clicking the button three times and then
            >click a picturebox, it's background colour will change.
            >>
            >Obviously you will have to implement a mechanism for varying the <xand
            ><y>
            >values otherwise all the pictureboxes will be drawn in the same place.
            >>
            >>
            ><toby@mkkbb.f9 .co.ukwrote in message
            >news:116787197 8.970527.168530 @31g2000cwt.goo glegroups.com.. .
            Hi there,
            >
            Is it possible to create an array of picturebox controls during
            run-time. I wish to create a new image/picturebox everytime a user
            clicks the button on a form, and they need to be objects so that the
            user can move/drag them around.
            >
            >
            The only examples I can find dont work as I am using VB Express (2005?)
            >
            and the examples are writting in VB6.
            >
            >
            Is anyone able to help please?
            >
            >
            Toby.
            >
            >
            Stepahnie,
            >
            How can I reference the image property of a picturebox in an array. I
            would ahve assumed it was:
            >
            m_picturebox(1) .image
            >
            but that brings up errors. How can I change properties of these
            controls in the array?
            >
            Thanks.
            >

            Comment

            Working...