Tile A Picture - Quick Source


Often times you want to just take a general background image and tile it across your form to give it a fancier look and feel. This is very easy to accomplish in Visual Basic. All you really need to do is add a picture to your form (called Picture1). Change the properties on the picture and select an image that you want to tile. A good place to find some samples is in your windows directory. Then add the following code:

  1. Dim X, Y, I, J As Single
  2. I = Picture1.ScaleWidth
  3. J = Picture1.ScaleHeight
  4. Y = 0
  5.     Do While Y < Form1.ScaleHeight
  6.     X = 0
  7.     Do While X < Form1.ScaleWidth
  8.     PaintPicture Picture1.Picture, X, Y, I, J
  9.     X = X + I
  10.     Loop
  11.     Y = Y + J
  12. Loop

The result will be that whatever picture you selected into Picture1 will be tiled across the entire form. Enjoy!

Obviously this just wets the palette with the beginning of what you can do with pictures in VB. If you want to learn more about using graphics in Visual Basic 6, I suggest you check out this tutorial: Pictures and such in VB6.

Note: The source for this was found at DreamVB which is no longer online.

If you enjoyed this post, subscribe for updates (it's free)