]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/paintevt.tex
fixed TeX error introduced in rev 48093 (sorry)
[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{Library}
20
21 \helpref{wxCore}{librarieslist}
22
23 \wxheading{Event table macros}
24
25 To process a paint event, use this event handler macro to direct input to a member
26 function that takes a wxPaintEvent argument.
27
28 \twocolwidtha{7cm}
29 \begin{twocollist}\itemsep=0pt
30 \twocolitem{{\bf EVT\_PAINT(func)}}{Process a wxEVT\_PAINT event.}
31 \end{twocollist}%
32
33 \wxheading{See also}
34
35 %\helpref{wxWindow::OnPaint}{wxwindowonpaint},
36 \helpref{Event handling overview}{eventhandlingoverview}
37
38 \wxheading{Remarks}
39
40 Note that In a paint event handler, the application must {\it always} create a \helpref{wxPaintDC}{wxpaintdc} object,
41 even if you do not use it. Otherwise, under MS Windows, refreshing for this and other windows will go wrong.
42
43 For example:
44
45 \small{%
46 \begin{verbatim}
47 void MyWindow::OnPaint(wxPaintEvent& event)
48 {
49 wxPaintDC dc(this);
50
51 DrawMyDocument(dc);
52 }
53 \end{verbatim}
54 }%
55
56 You can optimize painting by retrieving the rectangles
57 that have been damaged and only repainting these. The rectangles are in
58 terms of the client area, and are unscrolled, so you will need to do
59 some calculations using the current view position to obtain logical,
60 scrolled units.
61
62 Here is an example of using the \helpref{wxRegionIterator}{wxregioniterator} class:
63
64 {\small%
65 \begin{verbatim}
66 // Called when window needs to be repainted.
67 void MyWindow::OnPaint(wxPaintEvent& event)
68 {
69 wxPaintDC dc(this);
70
71 // Find Out where the window is scrolled to
72 int vbX,vbY; // Top left corner of client
73 GetViewStart(&vbX,&vbY);
74
75 int vX,vY,vW,vH; // Dimensions of client area in pixels
76 wxRegionIterator upd(GetUpdateRegion()); // get the update rect list
77
78 while (upd)
79 {
80 vX = upd.GetX();
81 vY = upd.GetY();
82 vW = upd.GetW();
83 vH = upd.GetH();
84
85 // Alternatively we can do this:
86 // wxRect rect(upd.GetRect());
87
88 // Repaint this rectangle
89 ...some code...
90
91 upd ++ ;
92 }
93 }
94 \end{verbatim}
95 }%
96
97
98 \latexignore{\rtfignore{\wxheading{Members}}}
99
100 \membersection{wxPaintEvent::wxPaintEvent}\label{wxpainteventctor}
101
102 \func{}{wxPaintEvent}{\param{int }{id = 0}}
103
104 Constructor.
105