Search Tools Links Login

Space Images in Background


Visual Basic 6, or VB Classic

Evenly spaces an image as many times as will fit on a form

Original Author: Shawn M. Hershman

Assumptions

1) Create a picture in the form and set it's INDEX property to 0 and it's VISIBLE property to false
2) SHOW the form before calling this subroutine

Side Effects

None I'm aware of

Code

Private Sub Space_Images()
Dim PicCols As Integer
Dim PicRows As Integer
Dim HExtraSpace As Integer
Dim VExtraSpace As Integer
Dim HSpacing As Integer
Dim VSpacing As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
On Error Resume Next
'Calculate the appropriate spacings
PicCols = CInt((Me.Width / picPicture(0).Width) - 0.5)
PicRows = CInt((Me.Height / picPicture(0).Height) - 0.5)
HExtraSpace = Me.Width - (picPicture(0).Width * PicCols)
VExtraSpace = Me.Height - (picPicture(0).Height * PicRows)
HSpacing = CInt((HExtraSpace / (PicCols + 1)) - 0.5)
VSpacing = CInt((VExtraSpace / (PicRows + 1)) - 0.5)

'Display the background images
For i = 0 To PicRows - 1
For j = 0 To PicCols - 1
  k = (PicCols * i) + j
  Load picPicture(k)
  picPicture(k).Left = (HSpacing * (j + 1)) + (picPicture(0).Width * j)
  picPicture(k).Top = (VSpacing * (i + 1)) + (picPicture(0).Height * i)
  picPicture(k).Visible = True
Next j
Next i

End Sub

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 95 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.