The wxTreebook (wxWidgets: wxTreebook Class Reference) control is a container for a set of pages that can be selected by selecting a node in a tree. The control is shown in Figure 1 below.

Figure 1: The wxTreebook Control

Simple Example

Below we show a simple example of a wxTreebook control. The example is a simple modification of the MinimalApp2 example we presented in the minimal application tutorial. The full source for this example is available from our GitHub repository: wxWidgetsTutorials/BookControls/WxTreebook1.

 File: BookControls/WxTreebook1/src/WxTreebook1Frame.cpp
#include "WxTreebook1Frame.h"
#include <wx/panel.h>
#include <wx/treebook.h>
#include <wx/sizer.h>

WxTreebook1Frame::WxTreebook1Frame(const wxString& title)
    : wxFrame(NULL, wxID_ANY, title)
    // Create a top-level panel to hold all the contents of the frame
    wxPanel* panel = new wxPanel(this, wxID_ANY);

    // Create a wxTreebook control
    wxTreebook* treebook = new wxTreebook(panel, wxID_ANY);

    // Create the first page and add it to the treebook
    wxPanel* page1 = new wxPanel(treebook, wxID_ANY);
    wxTextCtrl* textCtrl1 = new wxTextCtrl(page1, wxID_ANY,
        "Page 1 Text", wxDefaultPosition, wxSize(150, 50));
    wxBoxSizer* page1Sizer = new wxBoxSizer(wxHORIZONTAL);
    page1Sizer->Add(textCtrl1, 1, wxEXPAND);
    treebook->AddPage(page1, "Page 1");

    // Create the second page and add it to the treebook
    wxPanel* page2 = new wxPanel(treebook, wxID_ANY);
    wxTextCtrl* textCtrl2 = new wxTextCtrl(page2, wxID_ANY,
        "Page 2 Text", wxDefaultPosition, wxSize(150, 50));
    wxBoxSizer* page2Sizer = new wxBoxSizer(wxHORIZONTAL);
    page2Sizer->Add(textCtrl2, 1, wxEXPAND);
    treebook->AddPage(page2, "Page 2");

    // Set up the sizer for the panel
    wxBoxSizer* panelSizer = new wxBoxSizer(wxHORIZONTAL);
    panelSizer->Add(treebook, 1, wxEXPAND);

    // Set up the sizer for the frame and resize the frame
    // according to its contents
    wxBoxSizer* topSizer = new wxBoxSizer(wxHORIZONTAL);
    topSizer->SetMinSize(225, 100);
    topSizer->Add(panel, 1, wxEXPAND);

The application is shown in Figure 2 below.

Figure 2: The WxTreebook1 Application

The rest of the source files don't contain significant changes but are shown here for completeness.

 File: BookControls/WxTreebook1/src/WxTreebook1Frame.h

#include <wx/frame.h>

class WxTreebook1Frame : public wxFrame
    WxTreebook1Frame(const wxString& title);

 File: BookControls/WxTreebook1/src/WxTreebook1App.h

#include <wx/app.h>

class WxTreebook1App : public wxApp
    virtual bool OnInit();

 File: BookControls/WxTreebook1/src/WxTreebook1App.cpp
#include "WxTreebook1App.h"
#include "WxTreebook1Frame.h"


bool WxTreebook1App::OnInit()
    WxTreebook1Frame* frame = new WxTreebook1Frame(L"WxTreebook1");
    return true;