Tiling an image

how do I tile an image on the form making it look like a background?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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.
Éric MoreauSenior .Net ConsultantCommented:
I have this code to tile a bitmap from an image on a form:

Public Sub PaintBackground(ByRef pfrmDestination As Form)
Dim intFormHeight As Integer
Dim intFormWidth As Integer
Dim intImgHeight As Integer
Dim intImgWidth As Integer
Dim intX As Integer
Dim intY As Integer

    intFormHeight = pfrmDestination.Height
    intFormWidth = pfrmDestination.Width
    intImgWidth = frmAccueil.imgBackGround.Width
    intImgHeight = frmAccueil.imgBackGround.Height
    For intX = 0 To intFormWidth Step intImgWidth
        For intY = 0 To intFormHeight Step intImgHeight
'            Debug.Print intX & " - " & intY
            pfrmDestination.PaintPicture frmAccueil.imgBackGround, intX, intY
        Next intY
    Next intX
''    'tile left side (Method 2)
'    For intY = 0 To intFrmHeight Step intImgHeight
'        PaintPicture imgBackGround, 0, intY
'    Next intY
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day 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
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

mhdhallakAuthor Commented:
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.
Éric MoreauSenior .Net ConsultantCommented:
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.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.