Tile A Picture - Quick Source

Level:
Level1

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)

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo].

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.