Microsoft & .NETVisual BasicUsing Visual Basic to Tile a Bitmap in a Picture Box

Using Visual Basic to Tile a Bitmap in a Picture Box content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

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 

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories