本文主要是介绍38、wxWidgets小部件之wxSimpleBook,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、main.cpp
#include <wx/wx.h>
#include <wx/simplebook.h>
class Simple:public wxFrame
{
public:
Simple(const wxString& title);
protected:
void OnQuit(wxCommandEvent& event);
void OnChanged(wxBookCtrlEvent& event);
void OnBtn_Clicked(wxCommandEvent& event);
wxSimplebook* book;
long nCount;
};
二、mygrid.h
#ifndef MYGRID_H_INCLUDED
#define MYGRID_H_INCLUDED
#include <wx/wx.h>
#include <wx/bookctrl.h>
#include <wx/grid.h>
class MyGrid:public wxGrid
{
public:
MyGrid(wxBookCtrlBase* parent);
};
#endif // MYGRID_H_INCLUDED
三、mygrid.cpp
#include "mygrid.h"
MyGrid::MyGrid(wxBookCtrlBase* 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);
}
}
四、simple.h
#ifndef SIMPLE_H_INCLUDED
#define SIMPLE_H_INCLUDED
#include <wx/wx.h>
#include <wx/simplebook.h>
class Simple:public wxFrame
{
public:
Simple(const wxString& title);
protected:
void OnQuit(wxCommandEvent& event);
void OnChanged(wxBookCtrlEvent& event);
void OnBtn_Clicked(wxCommandEvent& event);
wxSimplebook* book;
long nCount;
};
#endif // SIMPLE_H_INCLUDED
五、simple.cpp
#include "simple.h"
#include "mygrid.h"
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 wxSimplebook(this,-1,wxPoint(-1,-1),wxSize(-1,-1));
book->SetImageList(ilMain);
// 效果设置,滚动到底部
book->SetEffect(wxSHOW_EFFECT_ROLL_TO_BOTTOM);
book->SetEffectsTimeouts(10, 5);
MyGrid* grid1 = new MyGrid(book);
MyGrid* grid2 = new MyGrid(book);
MyGrid* grid3 = new MyGrid(book);
book->AddPage(grid1,wxT("标签1"),false,0);
book->AddPage(grid2,wxT("标签2"),false,1);
book->ShowNewPage(grid3);
// book->SetSelection(2);//调用此函数会产生页面更改事件
// book->ChangeSelection(1);//调用此函数不产生页面更改事件
//
wxButton* btn = new wxButton(this,-1,"Change");
btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED,Simple::OnBtn_Clicked,this);
nCount=0;
Bind(wxEVT_BOOKCTRL_PAGE_CHANGED
,wxBookCtrlEventHandler(Simple::OnChanged)
,this
,book->GetId()
);
wxBoxSizer* hbox = new wxBoxSizer(wxHORIZONTAL);
hbox->Add(btn,1,wxEXPAND|wxALL,10);
hbox->Add(book,1,wxEXPAND|wxALL,0);
SetSizer(hbox);
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");
}
}
void Simple::OnBtn_Clicked(wxCommandEvent& event)
{
nCount+=1;
if(nCount>=book->GetPageCount()) nCount=0;
book->ChangeSelection(nCount);
book->Refresh();
}
这篇关于38、wxWidgets小部件之wxSimpleBook的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!