"Array" of pictureboxes

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

    #1

    "Array" of pictureboxes

    I'm going mad here. I know about creating controls at runtime and creating a
    single event etc. In all the examples I have found they create a button and
    create an event for it. What I can't fathom out is how to refer to a
    non-event control such as a picturebox. I have created them as follows:

    For n As Integer = 1 To 10

    Dim c As New PictureBox

    With c

    .Location() = New System.Drawing. Point(35, 30)

    .Size = New System.Drawing. Size(225, 175)

    .Name = "PictureBox " & Trim(Str(n))

    End With

    Me.Controls.Add (c)

    Next

    However, how do I now refer to it?

    PictureBox8.Ima ge = System.Drawing. Image.FromFile( MyPath & Filename)

    -Jerry


  • Peter Proost

    #2
    Re: "Array&quo t; of pictureboxes

    You would need something like this

    Private myPicBoxes as PictureBox (9)
    [color=blue]
    > For n As Integer = 1 To 10
    >
    > Dim c As New PictureBox
    >
    > With c
    >
    > .Location() = New System.Drawing. Point(35, 30)
    >
    > .Size = New System.Drawing. Size(225, 175)
    >
    > .Name = "PictureBox " & Trim(Str(n))
    >
    > End With
    >
    > Me.Controls.Add (c)[/color]

    myPicBoxes(n) = c
    [color=blue]
    >
    > Next[/color]

    myPicBoxes(8).I mage = System.Drawing. Image.FromFile( MyPath & Filename)


    Hope this helps

    --
    Programming today is a race between software engineers striving to build
    bigger and better idiot-proof programs, and the Universe trying to produce
    bigger and better idiots. So far, the Universe is winning. (Rich Cook)

    "Jerry Spence1" <jerry.spence@s omewhere.com> schreef in bericht
    news:44968e2b$0 $3526$ed2619ec@ ptn-nntp-reader01.plus.n et...[color=blue]
    > I'm going mad here. I know about creating controls at runtime and creating[/color]
    a[color=blue]
    > single event etc. In all the examples I have found they create a button[/color]
    and[color=blue]
    > create an event for it. What I can't fathom out is how to refer to a
    > non-event control such as a picturebox. I have created them as follows:
    >
    > For n As Integer = 1 To 10
    >
    > Dim c As New PictureBox
    >
    > With c
    >
    > .Location() = New System.Drawing. Point(35, 30)
    >
    > .Size = New System.Drawing. Size(225, 175)
    >
    > .Name = "PictureBox " & Trim(Str(n))
    >
    > End With
    >
    > Me.Controls.Add (c)
    >
    > Next
    >
    > However, how do I now refer to it?
    >
    > PictureBox8.Ima ge = System.Drawing. Image.FromFile( MyPath & Filename)
    >
    > -Jerry
    >
    >[/color]


    Comment

    • Cor Ligthert [MVP]

      #3
      Re: &quot;Array&quo t; of pictureboxes

      Jerry,

      Just put them in an array inside your procedure.
      See bellow (I changed it too from 0 to 9 a little bit more standard approach
      in Net.)

      Private c(9) as picturebox
      (I assume that you are using it in more procedures otherwise just dim inside
      the procedure)

      For n As Integer = 0 To 9
      Dim c(n) = New PictureBox
      With c(n)
      .Location() = New System.Drawing. Point(35, 30)
      .Size = New System.Drawing. Size(225, 175)
      .Name = "PictureBox " & Trim(Str(n))
      End With
      Me.Controls.Add (c(n))
      Next

      c(7).Image = System.Drawing. Image.FromFile( MyPath & Filename)

      Simple is it not?

      I would use another name than c by the way.

      :-)

      I hope this helps,

      Cor


      Comment

      • Jerry Spence1

        #4
        Re: &quot;Array&quo t; of pictureboxes

        Thank you Cor and Peter. Very grateful.

        Simple? Yea - it is now :)

        -Jerry


        "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> wrote in message
        news:%23p5QHe5k GHA.2280@TK2MSF TNGP02.phx.gbl. ..[color=blue]
        > Jerry,
        >
        > Just put them in an array inside your procedure.
        > See bellow (I changed it too from 0 to 9 a little bit more standard
        > approach in Net.)
        >
        > Private c(9) as picturebox
        > (I assume that you are using it in more procedures otherwise just dim
        > inside the procedure)
        >
        > For n As Integer = 0 To 9
        > Dim c(n) = New PictureBox
        > With c(n)
        > .Location() = New System.Drawing. Point(35, 30)
        > .Size = New System.Drawing. Size(225, 175)
        > .Name = "PictureBox " & Trim(Str(n))
        > End With
        > Me.Controls.Add (c(n))
        > Next
        >
        > c(7).Image = System.Drawing. Image.FromFile( MyPath & Filename)
        >
        > Simple is it not?
        >
        > I would use another name than c by the way.
        >
        > :-)
        >
        > I hope this helps,
        >
        > Cor
        >[/color]


        Comment

        • Jerry Spence1

          #5
          Re: &quot;Array&quo t; of pictureboxes

          Thank you Cor and Peter. Very grateful.

          Simple? Yea - it is now :)

          -Jerry


          "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> wrote in message
          news:%23p5QHe5k GHA.2280@TK2MSF TNGP02.phx.gbl. ..[color=blue]
          > Jerry,
          >
          > Just put them in an array inside your procedure.
          > See bellow (I changed it too from 0 to 9 a little bit more standard
          > approach in Net.)
          >
          > Private c(9) as picturebox
          > (I assume that you are using it in more procedures otherwise just dim
          > inside the procedure)
          >
          > For n As Integer = 0 To 9
          > Dim c(n) = New PictureBox
          > With c(n)
          > .Location() = New System.Drawing. Point(35, 30)
          > .Size = New System.Drawing. Size(225, 175)
          > .Name = "PictureBox " & Trim(Str(n))
          > End With
          > Me.Controls.Add (c(n))
          > Next
          >
          > c(7).Image = System.Drawing. Image.FromFile( MyPath & Filename)
          >
          > Simple is it not?
          >
          > I would use another name than c by the way.
          >
          > :-)
          >
          > I hope this helps,
          >
          > Cor
          >[/color]



          Comment

          • gene kelley

            #6
            Re: &quot;Array&quo t; of pictureboxes

            On Mon, 19 Jun 2006 12:44:42 +0100, "Jerry Spence1"
            <jerry.spence@s omewhere.com> wrote:
            [color=blue]
            >I'm going mad here. I know about creating controls at runtime and creating a
            >single event etc. In all the examples I have found they create a button and
            >create an event for it. What I can't fathom out is how to refer to a
            >non-event control such as a picturebox. I have created them as follows:
            >
            >For n As Integer = 1 To 10
            >
            > Dim c As New PictureBox
            >
            > With c
            >
            > .Location() = New System.Drawing. Point(35, 30)
            >
            > .Size = New System.Drawing. Size(225, 175)
            >
            > .Name = "PictureBox " & Trim(Str(n))
            >
            > End With
            >
            >Me.Controls.Ad d(c)
            >
            >Next
            >
            >However, how do I now refer to it?
            >
            >PictureBox8.Im age = System.Drawing. Image.FromFile( MyPath & Filename)
            >
            >-Jerry
            >[/color]

            Aside from the other responses, why do you say the PictureBox is a
            non-event control? It has a number of events.

            Gene

            Comment

            • Jerry Spence1

              #7
              Re: &quot;Array&quo t; of pictureboxes


              "gene kelley" <okay@by.me> wrote in message
              news:rfvd92tvcs qudgulcb6pqlqds qqi855li2@4ax.c om...[color=blue]
              > On Mon, 19 Jun 2006 12:44:42 +0100, "Jerry Spence1"
              > <jerry.spence@s omewhere.com> wrote:
              >[color=green]
              >>I'm going mad here. I know about creating controls at runtime and creating
              >>a
              >>single event etc. In all the examples I have found they create a button
              >>and
              >>create an event for it. What I can't fathom out is how to refer to a
              >>non-event control such as a picturebox. I have created them as follows:
              >>
              >>For n As Integer = 1 To 10
              >>
              >> Dim c As New PictureBox
              >>
              >> With c
              >>
              >> .Location() = New System.Drawing. Point(35, 30)
              >>
              >> .Size = New System.Drawing. Size(225, 175)
              >>
              >> .Name = "PictureBox " & Trim(Str(n))
              >>
              >> End With
              >>
              >>Me.Controls.A dd(c)
              >>
              >>Next
              >>
              >>However, how do I now refer to it?
              >>
              >>PictureBox8.I mage = System.Drawing. Image.FromFile( MyPath & Filename)
              >>
              >>-Jerry
              >>[/color]
              >
              > Aside from the other responses, why do you say the PictureBox is a
              > non-event control? It has a number of events.
              >
              > Gene
              >[/color]

              I mean it's a control that is the recipient of information rather than
              getting anythng from it such as a click etc.

              -Jerry


              Comment

              Working...