h1(#wxpaintevent). Wx::PaintEvent A paint event is sent when a window's contents needs to be repainted. h2. Derived from "Event":event.html "Object":object.html h2. Event table macros To process a paint event, use this event handler macro to direct input to a member function that takes a PaintEvent argument. |*evt_paint() { | event | ... }*|Process a EVT_PAINT event.| h2. See also "Event handling overview":eventhandlingoverview.html h2. Remarks Note that In a paint event handler, the application must _always_ create a "PaintDC":paintdc.html object, even if you do not use it. Otherwise, under MS Windows, refreshing for this and other windows will go wrong. For example: void MyWindow::OnPaint(PaintEvent& event) { PaintDC dc(this); DrawMyDocument(dc); } You can optimize painting by retrieving the rectangles that have been damaged and only repainting these. The rectangles are in terms of the client area, and are unscrolled, so you will need to do some calculations using the current view position to obtain logical, scrolled units. Here is an example of using the "RegionIterator":regioniterator.html class: // Called when window needs to be repainted. void MyWindow::OnPaint(PaintEvent& event) { PaintDC dc(this); // Find Out where the window is scrolled to int vbX,vbY; // Top left corner of client GetViewStart(&vbX,&vbY); int vX,vY,vW,vH; // Dimensions of client area in pixels RegionIterator upd(GetUpdateRegion()); // get the update rect list while (upd) { vX = upd.GetX(); vY = upd.GetY(); vW = upd.GetW(); vH = upd.GetH(); // Alternatively we can do this: // Rect rect(upd.GetRect()); // Repaint this rectangle ...some code... upd ++ ; } }