[Webinar] Streamline your web hosting managementRegister Today


Tiling an image

Posted on 1999-11-23
Medium Priority
Last Modified: 2010-05-02
how do I tile an image on the form making it look like a background?
Question by:mhdhallak

Expert Comment

ID: 2229979

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.
LVL 71

Accepted Solution

Éric Moreau earned 60 total points
ID: 2230155
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

Expert Comment

ID: 2230295
'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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.


Author Comment

ID: 2230338
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.

Expert Comment

ID: 2230773
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.
LVL 71

Expert Comment

by:Éric Moreau
ID: 2231140
Oh yes, as Jeremy_D said, my Picture control (imgBackGround) is set to AutoSize.
LVL 14

Expert Comment

ID: 2232802
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.


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

608 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question