Page 1 of 1

Couldn't draw polygon with wxDC:: DrawPolygon

Posted: Thu Mar 17, 2005 3:37 am
by samhwang
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?

Posted: Thu Mar 17, 2005 8:03 am
by Cursor
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