Visual Basic: Windows Controls

Visual Studio 6.0

Draw Method

See Also    Example    Applies To

Draws an image into a destination device context, such as a PictureBox control, after performing a graphical operation on the image.


object.Draw (hDC, x,y, style)

The Draw method syntax has these parts:

Part Description
object Required. An object expression that evaluates to an object in the Applies To list.
hDC Required. A value set to the target object's hDC property.
x,y Optional. The coordinates used to specify the location within the device context where the image will be drawn. If you don't specify these, the image is drawn at the origin of the device context.
style Optional. Specifies the operation performed on the image, as described in Settings.


The settings for style are:

Constant Value Description
imlNormal 0 (Default) Normal. Draws the image with no change.
imlTransparent 1 Transparent. Draws the image using the MaskColor property to determine which color of the image will be transparent.
imlSelected 2 Selected. Draws the image dithered with the system highlight color.
imlFocus 3 Focus. Draws the image dithered and striped with the highlight color creating a hatched effect to indicate the image has the focus.


The hDC property is a handle (a number) that the Windows operating system uses for internal reference to an object. You can paint in the internal area of any control that has an hDC property. In Visual Basic, these include the Form object, PictureBox control, and Printer object.

Because an object's hDC can change while an application is running, it is better to specify the hDC property rather than an actual value. For example, the following code ensures that the correct hDC value is always supplied to the ImageList control:

ImageList1.ListImages(1).Draw Form1.hDC