本文主要是介绍36、wxWidgets小部件之wxChoicebook,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
MyGrid请参照https://blog.csdn.net/sq8706/article/details/119638263
#include <wx/wx.h>
#include <wx/choicebk.h>
class Simple:public wxFrame
{
public:
Simple(const wxString& title);
protected:
void OnQuit(wxCommandEvent& event);
void OnChanged(wxBookCtrlEvent& event);
wxChoicebook* book;
wxChoice* choice;
};
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 wxChoicebook(this,-1,wxPoint(-1,-1),wxSize(-1,-1),wxNB_TOP);
book->SetImageList(ilMain);
choice = book->GetChoiceCtrl();
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_CHOICEBOOK_PAGE_CHANGED
,wxChoicebookEventHandler(Simple::OnChanged)
,this
,book->GetId()
);
CreateStatusBar();
Centre();
}
void Simple::OnChanged(wxBookCtrlEvent& event)
{
long index = choice->GetSelection();
if(index !=-1)
{
wxString str = choice->GetString(index);
wxMessageBox(str
,wxString::Format("ID=%i",index)
);
}
}
void Simple::OnQuit(wxCommandEvent& event)
{
Close(true);
}
这篇关于36、wxWidgets小部件之wxChoicebook的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!