一、Grid控件类
class MyGrid:public wxGrid
{
public:
MyGrid(wxNotebook* parent);
};
MyGrid::MyGrid(wxNotebook* parent)
:wxGrid(parent,-1)
{
CreateGrid(30,30);
SetRowLabelSize(50);
SetColLabelSize(25);
SetRowLabelAlignment(wxALIGN_RIGHT,wxALIGN_CENTER);
SetLabelFont(wxFont(9,wxFONTFAMILY_DEFAULT,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_BOLD));
for (int i=0;i<30;i++)
{
this->SetRowSize(i,25);
}
}
二、NoteBook类
class Simple:public wxFrame
{
public:
Simple(const wxString& title);
protected:
void OnQuit(wxCommandEvent& event);
};
Simple::Simple(const wxString& title)
:wxFrame(NULL,-1,title)
{
wxImage::AddHandler(new wxPNGHandler);
wxImageList* ilMain = new wxImageList(16,16);
ilMain->Add(wxBitmap("add.png",wxBITMAP_TYPE_PNG));
ilMain->Add(wxBitmap("del.png",wxBITMAP_TYPE_PNG));
ilMain->Add(wxBitmap("edit.png",wxBITMAP_TYPE_PNG));
wxNotebook* nb= new wxNotebook(this,-1,wxPoint(-1,-1),wxSize(-1,-1),wxNB_TOP);
nb->SetImageList(ilMain);
wxMenuBar* mbMain = new wxMenuBar;
wxMenu* mnFile = new wxMenu;
wxMenuItem* miQuit = new wxMenuItem(mnFile,-1,wxT("退出"));
mnFile->Append(miQuit);
mbMain->Append(mnFile,wxT("文件"));
SetMenuBar(mbMain);
Bind(wxEVT_COMMAND_MENU_SELECTED,Simple::OnQuit,this,miQuit->GetId());
MyGrid* grid1 = new MyGrid(nb);
MyGrid* grid2 = new MyGrid(nb);
MyGrid* grid3 = new MyGrid(nb);
nb->AddPage(grid1,wxT("标签1"));
nb->SetPageImage(0,0);
nb->AddPage(grid2,wxT("标签2"));
nb->SetPageImage(1,1);
nb->AddPage(grid3,wxT("标签3"));
nb->SetPageImage(2,2);
nb->SetSelection(2);//调用此函数会产生页面更改事件
nb->ChangeSelection(1);//调用此函数不产生页面更改事件
CreateStatusBar();
Centre();
}
void Simple::OnQuit(wxCommandEvent& event)
{
Close(true);
}