]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/paintevt.tex
Remove double entry of wxTrackable
[wxWidgets.git] / docs / latex / wx / paintevt.tex
CommitLineData
a660d684
KB
1\section{\class{wxPaintEvent}}\label{wxpaintevent}
2
3A paint event is sent when a window's contents needs to be repainted.
4
de9a4077
VZ
5Please notice that in general it is impossible to change the drawing of a
6standard control (such as \helpref{wxButton}{wxbutton}) and so you shouldn't
7attempt to handle paint events for them as even if it might work on some
8platforms, this is inherently not portable and won't work everywhere.
9
a660d684
KB
10\wxheading{Derived from}
11
12\helpref{wxEvent}{wxevent}\\
13\helpref{wxObject}{wxobject}
14
954b8ae6
JS
15\wxheading{Include files}
16
17<wx/event.h>
18
a7af285d
VZ
19\wxheading{Library}
20
21\helpref{wxCore}{librarieslist}
22
a660d684
KB
23\wxheading{Event table macros}
24
25To process a paint event, use this event handler macro to direct input to a member
26function 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
f4fcc291
JS
35%\helpref{wxWindow::OnPaint}{wxwindowonpaint},
36\helpref{Event handling overview}{eventhandlingoverview}
37
38\wxheading{Remarks}
39
40Note that In a paint event handler, the application must {\it always} create a \helpref{wxPaintDC}{wxpaintdc} object,
41even if you do not use it. Otherwise, under MS Windows, refreshing for this and other windows will go wrong.
42
43For example:
44
45\small{%
46\begin{verbatim}
5c180caf 47 void MyWindow::OnPaint(wxPaintEvent& event)
f4fcc291
JS
48 {
49 wxPaintDC dc(this);
50
51 DrawMyDocument(dc);
52 }
53\end{verbatim}
54}%
55
56You can optimize painting by retrieving the rectangles
57that have been damaged and only repainting these. The rectangles are in
58terms of the client area, and are unscrolled, so you will need to do
59some calculations using the current view position to obtain logical,
60scrolled units.
61
62Here is an example of using the \helpref{wxRegionIterator}{wxregioniterator} class:
63
64{\small%
65\begin{verbatim}
66// Called when window needs to be repainted.
5c180caf 67void MyWindow::OnPaint(wxPaintEvent& event)
f4fcc291
JS
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:
62b4ae08 86 // wxRect rect(upd.GetRect());
f4fcc291
JS
87
88 // Repaint this rectangle
89 ...some code...
90
91 upd ++ ;
92 }
93}
94\end{verbatim}
95}%
96
a660d684
KB
97
98\latexignore{\rtfignore{\wxheading{Members}}}
99
dcbd177f 100\membersection{wxPaintEvent::wxPaintEvent}\label{wxpainteventctor}
a660d684
KB
101
102\func{}{wxPaintEvent}{\param{int }{id = 0}}
103
104Constructor.
105