Populating panel with array of controls

How can I programmaticaly populate panel with array of picturebox controls?
I need to fill a form with number of images. I want to scrool the form and have two command buttons (OK and Cancel) always visible at the bottom of the form.

Comments

  • First of all, please look aat this link to see how to create an array of controls at run-time: http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=39&MsgID=229702&Setting=

    And the other one: http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=39&MsgID=227776&Setting=

    BTW, you might need to change the code in those links and use this code instead -> panel1.controls.add(Image1(i)) or some thing (I'm not sure, I haven't tested)

    As you add more Images, you should change the maximum of you VScroll1 Like this:
    [Code]
    'Ie, take the total hieght and divide it by the mount you wish to increment it by
    VScroll1.Maximum = ((Image1(image1.getupperindex(0)).top + Image1(image1.getupperindex(0)).Hieght) - Image1(0).Top) / 20
    [/Code]

    Here is how you should set your Verticle scrollbar:

    [Code]
    Private Sub VScroll1_Change(ByVal newScrollValue As Integer)
    For i = 0 To Image1.GetUpperBound(0)
    'Ie. Move the image by the [change in value] * increment
    Image1(i).Top += (vscroll1.value - newScrollValue) * 20
    If Image1(i).Top >= Panel1.top And Image1(i).Top <= panel1.top+panel1.hieght Then Image1(i).Visible = True Else Image1(i).Visible = False
    Next i
    End Sub
    [/Code]

    BTW, The /20 and *20 in the code are the amounts you wish to increment by - You can change them. (If you change ont, then change the other).

    I hope that helps!!!!!

    Relman

    : How can I programmaticaly populate panel with array of picturebox controls?
    : I need to fill a form with number of images. I want to scrool the form and have two command buttons (OK and Cancel) always visible at the bottom of the form.
    :

  • Thank you - it works.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories