本文主要是介绍34、wxWidgets小部件之wxNoteBook,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、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);
}
这篇关于34、wxWidgets小部件之wxNoteBook的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!