Link to home
Start Free TrialLog in
Avatar of mhdhallak
mhdhallak

asked on

Tiling an image

how do I tile an image on the form making it look like a background?
Avatar of Vbmaster
Vbmaster

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=893

www.planet-source-code.com is superb for these kind of standardized tasks. There are some additional codes too to archieve tiled bitmaps but this seems to be the most popular.
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
'tile an image on a form

'1) Place an image control on a form and give it a picture
'2) Set the forms AutoRedraw to False
'3) Place this code in the Form Paint Event

Dim intX As Integer
Dim intY As Integer

For intX = 0 To Me.Width Step Image1.Width
          For intY = 0 To Me.Height Step Image1.Height
              PaintPicture Image1, intX, intY
          Next intY
Next intX
Avatar of mhdhallak

ASKER

This is for emoreau,

I used your code and it did tile the image except that there was a little small gap between the tiled images.

Where specifically in your code can you delete this gap?

(Note: The gap is not caused by the image because the image tiled perfectly when I used it as a wallpaper.
emoreau uses imgBackGround.Height and .Width. What you should use is imgBackGround.Picture.Height and imgBackGround.Picture.Width. Or make sure the image control is borderless and autosizing.
Oh yes, as Jeremy_D said, my Picture control (imgBackGround) is set to AutoSize.
You can also just add the Microsoft Forms 2.0 Object library to your project and use the Image control that comes with the library.  There is a PictureTiling Property that you can set to true.

The picure will automatically be tiled to whatever the image size is...

You can add this to your project by right-clicking the toolbox and selecting "Components..." then select Microsoft Forms 2.0 Object library from the list.


Cheers!