+ if ( m_eraseBgInPaint )
+ {
+ dc.SetBackground(*wxLIGHT_GREY);
+ dc.Clear();
+
+ dc.DrawText("Background erased in OnPaint", 65, 110);
+ }
+ else if ( GetBackgroundStyle() == wxBG_STYLE_PAINT )
+ {
+ dc.SetTextForeground(*wxRED);
+ dc.DrawText("You must enable erasing background in OnPaint to avoid "
+ "display corruption", 65, 110);
+ }
+
+ dc.SetBrush( *wxBLACK_BRUSH );
+ dc.DrawRectangle( 10,10,60,50 );
+
+ dc.DrawBitmap( m_bitmap, 20, 20, true );
+
+ dc.SetTextForeground(*wxWHITE);
+ dc.DrawText("This text is drawn from OnPaint", 65, 65);
+
+ wxString tmp;
+ tmp.Printf("Hit any key to display more text: %s", m_text);
+
+ int w,h;
+ dc.GetTextExtent( tmp, &w, &h );
+ dc.DrawRectangle( 65, 85, w, h );
+ dc.DrawText( tmp, 65, 85 );
+}
+
+void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
+{
+ if ( m_useBuffer )
+ {
+ wxAutoBufferedPaintDC dc(this);
+ PrepareDC(dc);
+
+ DoPaint(dc);
+ }
+ else
+ {
+ wxPaintDC dc(this);
+ PrepareDC(dc);
+
+ DoPaint(dc);
+ }
+}
+
+void MyCanvas::OnEraseBackground( wxEraseEvent& event )
+{
+ wxASSERT_MSG
+ (
+ GetBackgroundStyle() == wxBG_STYLE_ERASE,
+ "shouldn't be called unless background style is \"erase\""
+ );
+
+ wxDC& dc = *event.GetDC();
+ dc.SetPen(*wxGREEN_PEN);
+
+ PrepareDC( dc );
+
+ // clear any junk currently displayed
+ dc.Clear();
+
+ const wxSize size = GetClientSize();
+ for ( int x = 0; x < size.x; x += 15 )
+ {
+ dc.DrawLine(x, 0, x, size.y);
+ }
+
+ for ( int y = 0; y < size.y; y += 15 )
+ {
+ dc.DrawLine(0, y, size.x, y);
+ }
+
+ dc.SetTextForeground(*wxRED);
+ dc.SetBackgroundMode(wxSOLID);
+ dc.DrawText("This text is drawn from OnEraseBackground", 60, 160);