]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/paintevt.tex
Fix "depreciated" to "deprecated".
[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
a660d684
KB
19\wxheading{Event table macros}
20
21To process a paint event, use this event handler macro to direct input to a member
22function 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
f4fcc291
JS
31%\helpref{wxWindow::OnPaint}{wxwindowonpaint},
32\helpref{Event handling overview}{eventhandlingoverview}
33
34\wxheading{Remarks}
35
36Note that In a paint event handler, the application must {\it always} create a \helpref{wxPaintDC}{wxpaintdc} object,
37even if you do not use it. Otherwise, under MS Windows, refreshing for this and other windows will go wrong.
38
39For example:
40
41\small{%
42\begin{verbatim}
5c180caf 43 void MyWindow::OnPaint(wxPaintEvent& event)
f4fcc291
JS
44 {
45 wxPaintDC dc(this);
46
47 DrawMyDocument(dc);
48 }
49\end{verbatim}
50}%
51
52You can optimize painting by retrieving the rectangles
53that have been damaged and only repainting these. The rectangles are in
54terms of the client area, and are unscrolled, so you will need to do
55some calculations using the current view position to obtain logical,
56scrolled units.
57
58Here is an example of using the \helpref{wxRegionIterator}{wxregioniterator} class:
59
60{\small%
61\begin{verbatim}
62// Called when window needs to be repainted.
5c180caf 63void MyWindow::OnPaint(wxPaintEvent& event)
f4fcc291
JS
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:
62b4ae08 82 // wxRect rect(upd.GetRect());
f4fcc291
JS
83
84 // Repaint this rectangle
85 ...some code...
86
87 upd ++ ;
88 }
89}
90\end{verbatim}
91}%
92
a660d684
KB
93
94\latexignore{\rtfignore{\wxheading{Members}}}
95
dcbd177f 96\membersection{wxPaintEvent::wxPaintEvent}\label{wxpainteventctor}
a660d684
KB
97
98\func{}{wxPaintEvent}{\param{int }{id = 0}}
99
100Constructor.
101