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