Painting Graphics at Arbitrary Locations

See Also

You can paint graphics at arbitrary locations on a form, on a picture box, and to the Printer object using the PaintPicture method. The syntax for the PaintPicture method is:

[object.]PaintPicture pic, destX, destY[, destWidth[, destHeight[, srcX _

[, srcY[, srcWidth[, srcHeight[, Op]]]]]]]

The destination object is the form, picture box, or Printer object where the pic picture is rendered. If object is omitted, the current form is assumed. The pic argument must be a Picture object, as from the Picture property of a form or control.

The destX and destY arguments are the horizontal and vertical locations where the picture will be rendered in the ScaleMode of object. The destWidth and destHeight arguments are optional and set the width and height with which the picture will be rendered in the destination object.

The srcX and srcY arguments are optional and define the x-coordinate and y-coordinate of the upper-left corner of a clipping region within pic.

The optional Op argument defines a raster operation (such as AND or XOR) that is performed on the picture as it is being painted on the destination object.

The PaintPicture method can be used in place of the BitBlt Windows API function to perform a wide variety of bit operations while moving a rectangular block of graphics from one position to any other position.

For example, you can use the PaintPicture method to create multiple copies of the same bitmap, and tile them on a form. Using this method is faster than moving picture controls on a form. The following code tiles 100 copies of a picture control and flips every picture horizontally by supplying a negative value for destWidth.

For i = 0 To 10
   For j = 0 To 10
      Form1.PaintPicture picF.Picture, j * _
         picF.Width, i * picF.Height, _
         picF.Width, -picF.Height
Next j, i

For More Information   See "PaintPicture Method" in the Language Reference.