?
#include <wx/wx.h> #include <wx/treebook.h> #include <wx/treectrl.h>
class Simple:public wxFrame { public: ? ? Simple(const wxString& title); protected: ? ? void OnQuit(wxCommandEvent& event); ? ? void OnChanged(wxBookCtrlEvent& event);
? ? wxTreebook* book; ? ? wxTreeCtrl* treeChild; };
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));
? ? book = new wxTreebook(this,-1,wxPoint(-1,-1),wxSize(-1,-1),wxNB_LEFT); ? ? book->SetImageList(ilMain); ? ? treeChild = book->GetTreeCtrl(); ? ? treeChild->SetMinSize(wxSize(100,100));//预留左侧树空间 // ? ?treeChild->SetMaxSize(wxSize(300,100));
? ? MyGrid* grid1 = new MyGrid(book); ? ? MyGrid* grid2 = new MyGrid(book); ? ? MyGrid* grid3 = new MyGrid(book);
? ? book->AddPage(grid1,wxT("标签1"),false,0); ? ? book->AddSubPage(grid3,wxT("1-1"),false,3); ? ? book->AddPage(grid2,wxT("标签2"),false,1); ? ? book->AddPage(grid3,wxT("标签3"),false,2);
? ? book->SetSelection(2);//调用此函数会产生页面更改事件 ? ? book->ChangeSelection(1);//调用此函数不产生页面更改事件
? ? Bind(wxEVT_TREEBOOK_PAGE_CHANGED ? ? ? ? ?,wxTreebookEventHandler(Simple::OnChanged) ? ? ? ? ?,this ? ? ? ? ?,book->GetId() ? ? ? ? ?); ? ? CreateStatusBar();
? ? Centre(); }
void Simple::OnChanged(wxBookCtrlEvent& event) { ? ? long index = book->GetSelection(); ? ? if(index !=-1) ? ? { ? ? ? ? wxMessageBox(book->GetPageText(index) ? ? ? ? ? ? ? ? ? ? ?,wxString::Format("ID=%i ",index) ? ? ? ? ? ? ? ? ? ? ?); ? ? }else ? ? { ? ? ? ? wxMessageBox("Not found"); ? ? } }
|