void MyCanvas::OnPaint(wxPaintEvent& event) { wxPaintDC dc(this); // Creates a Paint DC dc.SetBrush(wxBrush(wxColour(0, 0, 255))); // Blue fill brush dc.SetPen(wxPen(wxColour(0, 0, 0), 2)); // Black border pen dc.DrawRectangle(wxRect(10, 10, 50, 50)); // Draws a rectangle }
wxBitmap bitmap(100, 100); wxMemoryDC dc(bitmap); dc.SetBrush(wxBrush(wxColour(255, 0, 0))); // Red fill brush dc.DrawRectangle(wxRect(25, 25, 50, 50)); // Draws a rectangleIn both examples, wxDC DrawRectangle function is used to draw a rectangle on a drawing context with specified properties. The first example draws a rectangle on a window using a Paint DC, while the second example draws a rectangle on a bitmap using a Memory DC. The wxWidgets C++ library provides functionality to draw various shapes on different drawable surfaces.