See Also Example
Applies To
Form, common dialog
Description
Specifies a handle to the device context of an object; not available at design time and read-only at run time.
Usage
{ [form.] [commondialog. | picturebox. ] | Printer.}hDC
Remarks
This property is a Microsoft Windows environment device context handle. The Windows environment manages the system display by assigning a device context for the Printer object and for each form and picture box in your application. You can refer to the handle for an object's device context with the hDC property, which provides a value to pass to Windows API calls.
With a common dialog control, this property returns a device context for the printer selected in the Print dialog box when the PD_RETURNDC flag is set, or an information context when the PD_RETURNIC flag is set.
Note The value of the hDC property can change while a program is running. Therefore, you should not store the value in a variable; instead, use the hDC property each time you need it.
The AutoRedraw If AutoRedraw for a form or picture box is set to True, hDC acts as a handle to the device context of the persistent bitmap (equivalent to the Image property). When AutoRedraw is False, hDC is the actual hDC value of the Form window and the picture box window. Note that hDC may change while the program is running regardless of the AutoRedraw setting.
Data Type
Integer
Help:
hWnd Property
Icon Property
Programmer's Guide:
Chapter 22, "Calling Procedures in DLLs"
The example draws a triangle, and then uses a Windows function to fill it with color. Be sure that the declaration appears on one line with no break or wordwrap in the form module. To try this example, paste the code into the Declarations section of a form. Then press F5 and click the form.
' Declaration of Windows routine.
Declare Sub FloodFill Lib "GDI" (ByVal hDC As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal Color As Long)
Sub Form_Click ()
ScaleMode = 3 ' Windows draws in pixels.
ForeColor = 0 ' Set draw line to black.
Line (100, 50)-(300, 50) ' Draw a triangle.
Line -(200, 200)
Line -(100, 50)
FillStyle = 0 ' Set FillStyle to solid.
FillColor = RGB(128, 128, 255) ' Set FillColor.
FloodFill hDC, 200, 100, ForeColor ' Call Windows API to fill.
End Sub