Create an Image Array at Runtime...-VBForums
Results 1 to 1 of 1

Thread: Create an Image Array at Runtime...

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2003
    Posts
    62

    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.


    Code:
    ' 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
            End With
            
            L = L + 100 'Set next Left position (100 = width + padding)
            I = I + 1 'Increment Index number by 1
        Next
    
        T = T + 120 'Set next Top position (120 = height + padding)
        
    Next
    End Sub
    Last edited by Promocom; Mar 29th, 2012 at 11:34 PM. Reason: comment error

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.