Drawing pictureboxes problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MrMancunian
    Recognized Expert Contributor
    • Jul 2008
    • 569

    Drawing pictureboxes problem

    Hi,

    I'm facing a weird problem. I want to draw 15 pictureboxes in a horizontal line. I created an array of 15 boxes and in a loop, I assign it a picture and I set the location. Then I add the box to the form.

    Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim a, b As Integer
            Dim picLucifer(14) As PictureBox
            b = 1
            For a = 0 To 14
                picLucifer(a) = New PictureBox()
                picLucifer(a).Image = My.Resources.middlefinger
                picLucifer(a).Location = New Point(20, b)
                picLucifer(a).Visible = True
                b = b + 50
                Me.Controls.Add(picLucifer(a))
            Next
        End Sub
    Now, the problem is in the picLucifer(a).L ocation = New Point(20, b) row. When I assign a fixed value to the X and let the Y be a variable, everything is fine. I get a vertical list of 15 pictures. However, when I switch the X and the Y, so the X as variable and the Y fixed, it just shows me one picture. So,

    Code:
    picLucifer(a).Location = New Point(20, b)
    works, but

    Code:
    picLucifer(a).Location = New Point(b, 20)
    doesn't work. Does anyone have an idea why?

    Thanks!

    Steven
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Is there some "scrolling" property not set correctly on your Form object?
    Are your pictures really only <=50pixels wide?
    Did you set a breakpoint and verify that a unique point was being created for each picture?

    Nice choice of picture by the way.

    Comment

    • MrMancunian
      Recognized Expert Contributor
      • Jul 2008
      • 569

      #3
      Originally posted by Plater
      Is there some "scrolling" property not set correctly on your Form object?
      Are your pictures really only <=50pixels wide?
      Did you set a breakpoint and verify that a unique point was being created for each picture?

      Nice choice of picture by the way.
      There is no scrolling propery on the object. This is actually the only piece of code in the solution, as I am just trying and playing around. The size of the picture, which is an emoticon (http://www.stevenvandenbrink.nl/middlefinger.gif), is only 37 x 21. I set breakpoints and the integer b does change...

      Steven

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        Originally posted by MrMancunian
        There is no scrolling propery on the object. This is actually the only piece of code in the solution, as I am just trying and playing around. The size of the picture, which is an emoticon (http://www.stevenvandenbrink.nl/middlefinger.gif), is only 37 x 21. I set breakpoints and the integer b does change...

        Steven
        So when it does change, which of your 14 PictureBoxes is actually being placed? The first instance, the last?

        What about changing the calculation of your horizontal offset to include the Bounds.Left of the form its going onto? In theory the left edge should be zero, right? So it shouldn't make a difference whether you include it or not. But if the left edge has some weird geometry for some reason, and the left edge is -70, then your first several boxes will be drawn in a non-visible space.

        You might also consider using different images in each box so you can tell which box is being drawn in which location. Having them all come up as .middlefinger makes it harder to tell which is which.

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Must be a VB thing because mine worked fine?

          Also:
          New Point(20, b)
          Is the setup to produce a vertical grouping (one below the previous going downward) and not horizontal

          Comment

          • MrMancunian
            Recognized Expert Contributor
            • Jul 2008
            • 569

            #6
            Solved

            Hi,

            I solved the problem. I had to set the size of the picturebox to be the same as the image I put into the box. Thanks for the help :-)

            Steven

            Comment

            Working...