#include <wx/wx.h>
class Simple:public wxFrame
{
public:
Simple(const wxString& title);
protected:
void OnPaint(wxPaintEvent& event);
};
Simple::Simple(const wxString& title)
:wxFrame(NULL,-1,title,wxPoint(-1,-1),wxSize(680,580))
{
Bind(wxEVT_PAINT,wxPaintEventHandler(Simple::OnPaint),this);
Centre();
}
void Simple::OnPaint(wxPaintEvent& event)
{
wxPaintDC dc(this);
// 点
dc.SetPen(*wxBLACK);
dc.DrawPoint(50, 50);
wxCoord x=0,y=0;
for (int i = 0; i<1000; i++) {
x = rand() % GetSize().x + 1;
y = rand() % GetSize().y + 1;
dc.DrawPoint(x, y);
}
// 线
dc.SetPen(*wxBLUE_PEN);
dc.DrawLine(wxPoint(15, 15), wxPoint(75, 75));
dc.SetPen(*wxRED);
dc.DrawLine(60,100,190,100);//画线
// 矩形、圆角矩形
dc.SetPen(*wxBLUE);
dc.DrawRectangle(wxPoint(80, 35), wxSize(50, 45));
dc.SetPen(*wxBLUE);
dc.DrawRoundedRectangle(wxPoint(150,35),wxSize(50,50),10);
// 多边形
const wxPoint points[] = {
wxPoint(120, 120),
wxPoint(120, 260),
wxPoint(200, 260)
};
dc.SetPen(*wxYELLOW);
dc.SetBrush(*wxLIGHT_GREY);
dc.DrawPolygon(3, points);
// 圆
dc.SetPen(wxColour(59, 128, 59));
dc.SetBrush(wxColour(59, 128, 59));
dc.DrawCircle(wxPoint(280, 100), 80);
//渐变
dc.GradientFillLinear(wxRect(wxPoint(180,100),wxSize(100,100)),*wxWHITE,*wxBLUE,wxRIGHT);
// 文字
dc.DrawText(wxT("测试文字"), wxPoint(200, 160));
dc.SetFont(wxFont(10
,wxFONTFAMILY_SWISS
,wxFONTSTYLE_NORMAL
,wxFONTWEIGHT_BOLD
,false
,wxT("Arial")
)
);
dc.SetTextForeground(*wxBLUE);
dc.DrawText(wxT("中国加油"),50,120);
}