MyGrid请参照上一章https://blog.csdn.net/sq8706/article/details/119638263
#include <wx/wx.h>
#include <wx/listbook.h>
#include <wx/listctrl.h>
#include "mygrid.h"
class Simple:public wxFrame
{
public:
Simple(const wxString& title);
protected:
void OnQuit(wxCommandEvent& event);
void OnChanged(wxBookCtrlEvent& event);
wxListbook* book;
wxListView* lvBook;
};
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 wxListbook(this,-1,wxPoint(-1,-1),wxSize(-1,-1),wxNB_LEFT);
book->SetImageList(ilMain);
lvBook = book->GetListView();
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(book);
MyGrid* grid2 = new MyGrid(book);
MyGrid* grid3 = new MyGrid(book);
book->AddPage(grid1,wxT("标签1"));
book->SetPageImage(0,0);
lvBook->SetItemData(0,1);
book->AddPage(grid2,wxT("标签2"));
book->SetPageImage(1,1);
lvBook->SetItemData(1,2);
book->AddPage(grid3,wxT("标签3"));
book->SetPageImage(2,2);
lvBook->SetItemData(2,3);
book->SetSelection(2);//调用此函数会产生页面更改事件
book->ChangeSelection(1);//调用此函数不产生页面更改事件
Bind(wxEVT_LISTBOOK_PAGE_CHANGED
,wxListbookEventHandler(Simple::OnChanged)
,this
,book->GetId()
);
CreateStatusBar();
Centre();
}
void Simple::OnChanged(wxBookCtrlEvent& event)
{
long index = lvBook->GetFirstSelected();
if(index !=-1)
{
wxListItem li;
long nData = lvBook->GetItemData(index);
wxMessageBox(lvBook->GetItemText(index,0)
,wxString::Format("ID=%i Data=%i",index,nData)
);
}
}
void Simple::OnQuit(wxCommandEvent& event)
{
Close(true);
}