class Simple:public wxFrame
{
public:
Simple(const wxString& title);
protected:
wxSlider* slider;
wxBitmapButton* button;
int pos;
void OnScroll(wxScrollEvent& event);
};
Simple::Simple(const wxString& title)
:wxFrame(NULL,-1,title)
{
wxLog::SetLogLevel(0);//不用报警:iccp:known incorrect srgb profile
wxImage::AddHandler(new wxPNGHandler);
pos =0;
wxPanel* panel = new wxPanel(this);
slider = new wxSlider(panel,-1,0,0,100,wxPoint(10,30),wxSize(140,-1));
button= new wxBitmapButton(this,-1
,wxBitmap("edit-add.png",wxBITMAP_TYPE_PNG)
,wxPoint(180,30),wxSize(60,40)
,wxBU_RIGHT
);
button->SetLabel("label");
//button->SetWindowStyle(button->GetWindowStyle() &(~wxBU_NOTEXT));//网上有这么用的
button->SetWindowStyle(button->GetWindowStyle() & wxCAPTION);
Bind(wxEVT_COMMAND_SLIDER_UPDATED,wxScrollEventHandler(Simple::OnScroll)
,this,slider->GetId());
Centre();
}
void Simple::OnScroll(wxScrollEvent& event)
{
pos = slider->GetValue();
if (pos == 0)
{
button->SetBitmapLabel(wxBitmap(wxT("edit-add.png"), wxBITMAP_TYPE_PNG));
}
else if (pos > 0 && pos <= 30 )
{
button->SetBitmapLabel(wxBitmap(wxT("edit-add-2.png"), wxBITMAP_TYPE_PNG));
}
else if (pos > 30 && pos < 80 )
{
button->SetBitmapLabel(wxBitmap(wxT("edit-add-3.png"), wxBITMAP_TYPE_PNG));
}
else
{
button->SetBitmapLabel(wxBitmap(wxT("edit-add-4.png"), wxBITMAP_TYPE_PNG));
}
}