MyFrame.h
#pragma once
#include <wx/wx.h>
class MyApp:public wxApp{
public:
virtual bool OnInit();
};
DECLARE_APP(MyApp);
class MyFrame:public wxFrame
{
public:
MyFrame(const wxString& title);
~MyFrame(void);
private:
void test_boxsizer();
void test_staticboxsizer();
void test_wrapsizer();
void aftersizer(wxSizer* top);
};
MyFrame.cpp
#include "MyFrame.h"
#include "MyDialog.h"
#include <wx/wrapsizer.h>
IMPLEMENT_APP(MyApp);
bool
MyApp::OnInit(){
wxFrame* m = new MyFrame("Box1");
m->Show(true);
MyDialog* dlg = new MyDialog("Dialog Test");
dlg->Show(true);
return true;
}
MyFrame::~MyFrame(void)
{
}
MyFrame::MyFrame(const wxString& title)
:wxFrame(NULL, wxID_ANY, title)
{
test_boxsizer();
}
void
MyFrame::test_boxsizer(){
//wxBoxSizer* mysizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer* mysizer = new wxBoxSizer(wxVERTICAL);
wxButton* btn1 = new wxButton(this,-1,"btn1", wxPoint(0,0), wxSize(100,50));
mysizer->Add(btn1, 0,wxALL, 5);
wxButton* btn2 = new wxButton(this,-1,"btn2" );
mysizer->Add(btn2, 0,wxALL|wxCENTER, 5);
wxButton* btn3 = new wxButton(this,-1,"btn3" );
mysizer->Add(btn3, 1,wxALL|wxEXPAND, 5);
wxSizerFlags flags;
flags.Proportion(1);
flags.Border(wxALL,10);
flags.Center();
flags.Expand();
wxButton* btn4 = new wxButton(this,-1,"wxSizerFlags" );
mysizer->Add( btn4, flags);
aftersizer(mysizer);
}
void
MyFrame::test_wrapsizer(){
wxWrapSizer* m = new wxWrapSizer(wxHORIZONTAL,wxREMOVE_LEADING_SPACES);
for(int i=0;i<10;++i){
wxButton* btn = new wxButton(this,wxID_ANY, wxString::Format("btn %d", i) );
m->Add(btn,1,wxALL|wxEXPAND,5);
}
aftersizer(m);
}
void
MyFrame::test_staticboxsizer(){
wxStaticBoxSizer* mysizer = new wxStaticBoxSizer(wxHORIZONTAL,this,"Label ...");
wxWindow* parent = mysizer->GetStaticBox();
wxButton* btn1 = new wxButton(parent,-1,"btn1", wxPoint(0,0), wxSize(100,50));
mysizer->Add(btn1, 0,wxALL, 5);
wxButton* btn2 = new wxButton(parent,-1,"btn2" );
mysizer->Add(btn2, 0,wxALL|wxCENTER, 5);
wxButton* btn3 = new wxButton(parent,-1,"btn3" );
mysizer->Add(btn3, 1,wxALL|wxEXPAND, 5);
aftersizer(mysizer);
}
void
MyFrame::aftersizer(wxSizer* top){
this->SetSizer(top);
this->Layout();
this->Fit();
this->SetAutoLayout(