Search code examples
winformspaint

WinForms paint cycle documentation?


Is there documentation on the paint cycle in WinForms?

When i am programming in Windows the paint cycle is usually of the form:

sent a WM_PAINT message
{
   call BeginPaint(&paintStruct)

      //BeginPaint sends WM_NCPAINT and WM_ERASEBKGND
      sent a WM_ERASEBKGND message
      {
         i can:
           - allow default processing (Windows will fill the area with the default background color (e.g. white)
           - erase and background myself (e.g. a gradient) and prevent default processing
           - do nothing (letting whatever was there before me stay there) and prevent default processing
      }

   perform whatever painting i desire on 
         paintStruct.hDC (Device Context)
         paintStruct.rcPaint (Invalid Rectangle)
   that was populated into paintStruct during BeginPaint

   call EndPaint()
}

This is all documented on MSDN: Windows Development\Graphics and Multimedia\Windows GDI\Painting and Drawing\About Painting and Drawing

i cannot find any such documentation about WinForms and its paint cycle. i can randomly find methods and events that have the name paint in them:

  • OnPaint (protected method "Raises the Paint event.")
  • OnPrint (protected method "Raises the Paint event.")
  • InvokePaint (protected method "Raises the Paint event for the specified control.")
  • Paint (public event)
  • InvokePaintBackground (protected method "Raises the PaintBackground event for the specified control.")
  • OnPaintBackground (protected method "Paints the background of the control.")

Note: Ignoring the fact that there is no PaintBackground event

Is there documentation describing the design relationship between these entities? Is there documentation on the paint cycle in WinForms?


Solution

  • Is this what you are looking for?

    MSDN: Custom Control Painting and Rendering


    OP Edit: For when Microsoft implements their next round of link breaking, the documentation's location is:

    • MSDN Library
      • Development Tools and Languages
        • Visual Studio 2010
          • Visual Studio
            • Creating Windows-Based Applications
              • Windows Forms
                • Getting Started with Windows Forms
                  • Windows Forms Controls
                    • Development Custom Windows Forms Controls with the .NET Framework
                      • Custom Control Painting and Rendering