]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/paintevt.tex
add Create to wxDocParentFrame
[wxWidgets.git] / docs / latex / wx / paintevt.tex
1 \section{\class{wxPaintEvent}}\label{wxpaintevent}
2
3 A paint event is sent when a window's contents needs to be repainted.
4
5 Please notice that in general it is impossible to change the drawing of a
6 standard control (such as \helpref{wxButton}{wxbutton}) and so you shouldn't
7 attempt to handle paint events for them as even if it might work on some
8 platforms, this is inherently not portable and won't work everywhere.
9
10 \wxheading{Derived from}
11
12 \helpref{wxEvent}{wxevent}\\
13 \helpref{wxObject}{wxobject}
14
15 \wxheading{Include files}
16
17 <wx/event.h>
18
19 \wxheading{Event table macros}
20
21 To process a paint event, use this event handler macro to direct input to a member
22 function that takes a wxPaintEvent argument.
23
24 \twocolwidtha{7cm}
25 \begin{twocollist}\itemsep=0pt
26 \twocolitem{{\bf EVT\_PAINT(func)}}{Process a wxEVT\_PAINT event.}
27 \end{twocollist}%
28
29 \wxheading{See also}
30
31 %\helpref{wxWindow::OnPaint}{wxwindowonpaint},
32 \helpref{Event handling overview}{eventhandlingoverview}
33
34 \wxheading{Remarks}
35
36 Note that In a paint event handler, the application must {\it always} create a \helpref{wxPaintDC}{wxpaintdc} object,
37 even if you do not use it. Otherwise, under MS Windows, refreshing for this and other windows will go wrong.
38
39 For example:
40
41 \small{%
42 \begin{verbatim}
43 void MyWindow::OnPaint(wxPaintEvent& event)
44 {
45 wxPaintDC dc(this);
46
47 DrawMyDocument(dc);
48 }
49 \end{verbatim}
50 }%
51
52 You can optimize painting by retrieving the rectangles
53 that have been damaged and only repainting these. The rectangles are in
54 terms of the client area, and are unscrolled, so you will need to do
55 some calculations using the current view position to obtain logical,
56 scrolled units.
57
58 Here is an example of using the \helpref{wxRegionIterator}{wxregioniterator} class:
59
60 {\small%
61 \begin{verbatim}
62 // Called when window needs to be repainted.
63 void MyWindow::OnPaint(wxPaintEvent& event)
64 {
65 wxPaintDC dc(this);
66
67 // Find Out where the window is scrolled to
68 int vbX,vbY; // Top left corner of client
69 GetViewStart(&vbX,&vbY);
70
71 int vX,vY,vW,vH; // Dimensions of client area in pixels
72 wxRegionIterator upd(GetUpdateRegion()); // get the update rect list
73
74 while (upd)
75 {
76 vX = upd.GetX();
77 vY = upd.GetY();
78 vW = upd.GetW();
79 vH = upd.GetH();
80
81 // Alternatively we can do this:
82 // wxRect rect(upd.GetRect());
83
84 // Repaint this rectangle
85 ...some code...
86
87 upd ++ ;
88 }
89 }
90 \end{verbatim}
91 }%
92
93
94 \latexignore{\rtfignore{\wxheading{Members}}}
95
96 \membersection{wxPaintEvent::wxPaintEvent}\label{wxpainteventctor}
97
98 \func{}{wxPaintEvent}{\param{int }{id = 0}}
99
100 Constructor.
101