hDC Property Example

This example draws a triangle and then uses a Microsoft Windows function to fill it with color. To try this example, create a new module using the Add Module command on the Project menu. Paste the Declare statement into the Declarations section of the new module, being sure that the statement is on one line with no break or wordwrap. Then paste the Sub procedure into the Declarations section of a form. Press F5 and click the form.

' Declaration of a Windows routine. This statement is
' for the module.
Declare Sub FloodFill Lib "GDI32" Alias "FloodFill" _
 (ByVal hDC As Long, ByVal X As Long, ByVal Y As _
 Long, ByVal crColor As Long) As Long
' Place the following code in the form.
Private Sub Form_Click ()
   ScaleMode = vbPixels     ' Windows draws in pixels.
   ForeColor = vbBlack     ' Set draw line to black.
   Line (100, 50)-(300, 50) ' Draw a triangle.
   Line -(200, 200)
   Line -(100, 50)
   FillStyle = vbFSSolid  ' Set FillStyle to solid.
   FillColor = RGB(128, 128, 255)   ' Set FillColor.
 ' Call Windows API to fill.
   FloodFill hDC, 200, 100, ForeColor 
End Sub