October 27, 2016
Hot Topics:

Using Visual Basic to Tile a Bitmap in a Picture Box

  • November 18, 2002
  • By Sam Huggill
  • Send Email »
  • More Articles »
Private Declare Function _
     BitBlt _
   Lib "GDI32" (ByVal hDestDC As Integer, _
                ByVal X As Integer, _
                ByVal Y As Integer, _
                ByVal nWid As Integer, _
                ByVal nHt As Integer, _
                ByVal hSrcDC As Integer, _
                ByVal XSrc As Integer, _
                ByVal YSrc As Integer, _
            ByVal dwRop As Long) As Integer 

Private Sub Tile( picParent As PictureBox, _
                  picTile As PictureBox) 
'// This subroutine tiles a picture onto 
'// another picture. 
'// Call syntax: Tile Picture1, Picture2 
'// Tile (destination), (source) 
Dim TileIt As Integer 
Const SRCCOPY = &HCC0020 
Dim X As Integer, Y As Integer 
Dim MaximumX As Integer, MaximumY As Integer 

MaximumX = picParent.Width + picTile.Width 
MaximumY = picParent.Height + picTile.Height 
MaximumX = MaximumX \Screen.TwipsPerPixelX 
MaximumY = MaximumY \Screen.TwipsPerPixelY 

Dim TileWidth As Integer, TileHeight As Integer 

TileWidth = picTile.Width \Screen.TwipsPerPixelX 
TileHeight = picTile.Height \Screen.TwipsPerPixelY 

For Y = 0 To MaximumY Step TileHeight 
For X = 0 To MaximumX Step TileWidth 
TileIt = BitBlt(picParent.hDC, X, Y, _
                TileWidth, TileHeight, _
                picTile.hDC, 0, 0, SRCCOPY) 
End Sub 

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel