Mar 10th, 2012, 07:25 PM
Create an Image Array at Runtime...
I used to struggle with copying and pasting and aligning controls to make multiple rows and columns of images on forms for graphical catalogs and collections etc. Then I learned how to create the controls at runtime easily with just a few lines of code. This code will create a 5 X 4 array of image controls, but you can easily change it for any controls you want in rows and columns.
' Set the forms scalemode to Pixel. Then place an Image control with
' the attributes you choose on the form and name it "Pic" and give
' it an Index of 0. You can make it invisible or hide it off the
' edge of the form. (My control had a height of 100 & width of 80)
Private Sub Form_Load()
'This will create an 5 X 4 array of image controls
Dim I As Long 'Index
Dim T As Long 'Top
Dim L As Long 'Left
T = 25 'Set starting Top position
I = 1 'Set starting Index number
For r = 1 To 4 'Set number of Rows
L = 25 'Set starting Left position
For c = 1 To 5 'Set number of Columns
Load Pic(I) 'Load new image named Pic and assign Index number
With Pic(I) 'Set where next image will be created and make it visible
.Visible = True
.BorderStyle = 1
.Top = T
.Left = L
L = L + 100 'Set next Left position (100 = width + padding)
I = I + 1 'Increment Index number by 1
T = T + 120 'Set next Top position (120 = height + padding)
Last edited by Promocom; Mar 29th, 2012 at 10:34 PM.
Reason: comment error
Click Here to Expand Forum to Full Width
Survey posted by VBForums.