Copyright © 1998-2010 MultiMedia Soft

PaintDone event

Previous pageReturn to chapter overviewNext page


Occurs immediately after the completion of the control graphical rendering. Catching this event will allow to make further rendering on the control surface through the hDC parameter.

For further details about custom graphic rendering see the How to perform custom graphic rendering over the control surface section.



Visual Basic

BtnEnh1_PaintDone (ByVal hDC As Long)


Visual C++

void PaintDone (long hDC);







Handle to the screen device context: the drawback with using a screen device context is the fact that the rendering won't be flicker free. Use the SetCustomPaintFunction method in order to perform flicker free rendering.


It's important to note that each of the available controls can have a different drawing function.


Let's see a sample that demonstrates how to paint a red circle over the button surface:


Visual Basic example

Inside a BAS module, add the following declarations that will allow accessing the Windows GDI primitives

Public Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long

Public Declare Function Ellipse Lib "gdi32" (ByVal hDC As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long

Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject&) As Long

Public Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long

Inside the same BAS module add the following subroutine that will perform our custom rendering

Sub MyPaintFunction(ByVal hDC As Long)

 Dim brushColor As Long

 Dim brushOld As Long

 brushColor = CreateSolidBrush(RGB(255, 0, 0))

 brushOld = SelectObject(hDC, brushColor)

 Ellipse hDC, 10, 10, 50, 50

 SelectObject hDC, brushOld

 DeleteObject brushColor

End Sub

Inside the form code, catch the PaintDone event for the control BtnEnh1 and call the MyPaintFunction subroutine declared above

Private Sub BtnEnh1_PaintDone(ByVal hDC As Long)

 MyPaintFunction hDC

End Sub



Visual C++ example

Supposing that we have a dialog box with a button identified by IDC_BTNENHCTRL1, let's add the management function for the PaintDone event




     ON_EVENT(CMyDialog, IDC_BTNENHCTRL1, 11 /* PaintDone */, OnPaintDoneBtnenhctrl1, VTS_I4)



The OnPaintDoneBtnenhctrl1management function will look like this:

void CMyDialog::OnPaintDoneBtnenhctrl1(long hDC)


     HBRUSH brushColor = ::CreateSolidBrush (RGB (255,0,0));

     HBRUSH brushOld = (HBRUSH) ::SelectObject ((HDC) hDC, brushColor);

     ::Ellipse((HDC) hDC, 10, 10, 50, 50);

     ::SelectObject ((HDC) hDC, brushOld);

     ::DeleteObject (brushColor);