OVERVIEW
A wxNotebook is basically a tab control which lets you group controls together in tab sections. In the sample code below, we create a mini-spreadsheet application by having a wxGrid control in each tab. Rather than create separate wxGrid controls for each tab, we define an array of wxGrid controls and create them in a loop. wxGrid is dealt with in more detail in a later section.
SAMPLE CODE
notebook.h
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/notebook.h>
#include <wx/grid.h>
class Notebook: public wxFrame {
public:
Notebook(const wxString &title);
private:
wxNotebook *mNotebook;
wxGrid *mGrid[5];
};
notebook.cpp
#include "notebook.h"
Notebook::Notebook(const wxString &title):
wxFrame(NULL, -1, title, wxDefaultPosition, wxSize(700,550)) {
mNotebook = new wxNotebook(this, -1, wxDefaultPosition, wxDefaultSize, wxNB_BOTTOM);
wxString stitle;
for(int i = 0; i < 5; i++) {
mGrid[i] = new wxGrid(mNotebook, -1);
mGrid[i]->CreateGrid(20,30);
mGrid[i]->SetRowLabelSize(50);
mGrid[i]->SetColLabelSize(25);
mGrid[i]->SetRowLabelAlignment(wxALIGN_RIGHT, wxALIGN_CENTER);
for(int r = 0; r < 20; r++) {
mGrid[i]->SetRowSize(r, 25);
}
stitle = "Sheet ";
stitle.Append(wxString::Format(wxT("%d"), (i+1)));
mNotebook->AddPage(mGrid[i], stitle);
}
Center();
}
main.h
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
class Main: public wxApp {
public:
virtual bool OnInit();
};
main.cpp
#include "main.h"
#include "notebook.h"
IMPLEMENT_APP(Main)
bool Main::OnInit() {
Notebook *app = new Notebook(wxT("NoteBook"));
app->Show(true);
}
The output is shown below
Leave a Reply