When you need to perform custom painting in Windows Forms, implement an event handler for the Paint event for Windows Forms controls. The Paint event is passed an object indicating which event raised the event and a second argument, PaintEventArgs. PaintEventArgs has a Graphics object property that is the Graphics object of the control that raised the event.
Listing 17.1 demonstrates an example where a form's Paint event is used to create a shadow effect for a string. If you find yourself writing a paint event handler to create custom effects, consider subclassing a control to make those custom paint effects permanent. (Refer to Chapter 16, "Designing User Interfaces," for advanced topics.)
Additionally, Listing 17.11 demonstrates painting the selected Bitmap in the Paint event. When a bitmap is painted directly to the form without a control, we need to paint the image in the Paint event to ensure that the Bitmap is repainted when the form is invalidated. If the Bitmap were rendered in a control, the control would receive a WM_PAINT message when its owning form was invalidated and would repaint itself.