class TestStaticText:public wxFrame
{
public:
TestStaticText(const wxString& title);
protected:
void OnPaint(wxPaintEvent& event);
int f;
wxStaticText* st;
wxStaticLine* sl;
};
TestStaticText::TestStaticText(const wxString& title)
:wxFrame(NULL,-1,title)
{
SetBackgroundColour(*wxLIGHT_GREY);
wxString text = wxT("测试文本\n");
text.Append( wxT("第二行\n"));
st = new wxStaticText(this,-1,text);
st->SetForegroundColour(*wxRED);;
st->SetLabel(st->GetLabel() + "Red text\n");
// st->SetBackgroundStyle(wxBG_STYLE_PAINT);
sl = new wxStaticLine(this,-1,wxPoint(-1,-1),wxSize(-1,10));
wxClientDC dc(sl);
wxBrush brush1(wxColour(197, 108, 0));
dc.SetBrush(brush1);
dc.DrawRectangle(sl->GetClientRect());
sl->Refresh();
wxBoxSizer* szMain = new wxBoxSizer(wxVERTICAL);
szMain->Add(st,0,wxEXPAND|wxALL,10);
szMain->Add(sl,0,wxEXPAND|wxALL,10);
SetSizer(szMain);
f=28;
Bind(wxEVT_PAINT,wxPaintEventHandler(TestStaticText::OnPaint),this);
Centre();
}
void TestStaticText::OnPaint(wxPaintEvent& event)
{
wxPaintDC dc(this);
wxPen pen(wxColour(212, 212, 212));
dc.SetPen(pen);
dc.DrawRectangle(wxRect(140, 150, 100, 100));
wxBrush brush1(wxColour(197, 108, 0));
dc.SetBrush(brush1);
dc.DrawRectangle(wxRect(140, 150, 100, f));
//给wxStaticLine上色
wxClientDC dcSL(sl);
wxBrush brushSL(wxColour(197, 108, 0));
dcSL.SetBrush(brushSL);
dcSL.DrawRectangle(sl->GetClientRect());
}