Couldn't draw polygon with wxDC:: DrawPolygon

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
samhwang
In need of some credit
In need of some credit
Posts: 9
Joined: Wed Mar 09, 2005 3:54 pm

Couldn't draw polygon with wxDC:: DrawPolygon

Post by samhwang » Thu Mar 17, 2005 3:37 am

I use the following code to present a polygon:

wxDC dc;

wxPoint *points = GetPoints();
MyFrame *frame = new MyFrame();
frame->PrepareDC(dc);

dc.BeginDrawing();
dc.SetPen(*wxCYAN_PEN);
dc.DrawPolygon(size, points);
dc.EndDrawing();

frame->Show(true);

But the frame had not display any polygons, what was wrong?

Cursor
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Aug 29, 2004 3:09 pm
Location: Grenoble, France
Contact:

Post by Cursor » Thu Mar 17, 2005 8:03 am

Here is you writing code ? Is it in wxPaintEvent handling ?

At the end of your code, you use a frame->Show witch show the window and refresh its content.
You can draw on a window where you want but if you don not draw it in a wxPaintEvent handling function, yours modifs will be discarded.

You must write :

void MyWindow::OnPaint(wxPaintEvent &)
{
wxPaintDC dc(this);
dc.BeginDrawing();
dc.SetPen(*wxCYAN_PEN);
dc.DrawPolygon(size, points);
dc.EndDrawing();
}

and intercept it :

BEGIN_EVENT_TABLE(MyWindow, ...)
EVT_PAINT (MyWindow::OnPaint)
// ...
END_EVENT_TABLE()

see : http://www.wxwidgets.org/manuals/2.5.4/ ... #wxpaintdc

Post Reply