wxNotebook

From WxWiki
Jump to: navigation, search
Official Classes SmallBlocks.png Archive Containers Controls Data Structures Database Date & Time Debug Device Contexts Dialogs Document & Views Drag & Drop Events Filesystem Frames Graphics Grid Cell Help HTML Logging Miscellaneous Networking Printing Sizers Streams Threading Windows

This class represents a notebook control, which manages multiple windows with associated tabs.

To use the class, create a wxNotebook object and call wxNotebook::AddPage or wxNotebook::InsertPage, passing a window to be used as the page. Do not explicitly delete the window for a page that is currently managed by wxNotebook.

wxNotebookPage is a typedef for wxWindow.

Pitfalls

EVT_NOTEBOOK_PAGE_CHANGING Fired Before Dialog is Ready

If you are using EVT_NOTEBOOK_PAGE_CHANGING in your event table, there will be an EVT_NOTEBOOK_PAGE_CHANGING as the dialog is being constructed. If the function you have connected to this event manipulates some controls, those controls may not exist yet, so you can crash.

One way around this is to just insert a check in your function to verify that the dialog is visible. For example:

if ( this->wxWindow::IsShown() )
{
     // some code to manipulate the controls on the dialog's notebook
}

The dialog is only shown after everything is created, so the actions tied to the event will now only execute when the controls are actually created.

Put Notebooks in Panels

As with other widgets, it's usually a bad idea to put a wxNotebook directly in a wxFrame. It's better to put a wxPanel in the wxFrame, and then put the wxNotebook in the wxPanel


Layout Multiline Notebooks

If I use the wxNB_MULTILINE style, I cannot see the second line of tabs unless I call wxNotebook::Layout() after adding the pages. This does not seem to be in the documentation.

myNotebook = new wxNotebook( this, IDC_NOTEBOOK, wxDefaultPosition, wxSize(500, 500), wxNB_MULTILINE );
myNotebook->AddPage( new wxNotebookPage( myNotebook, -1 ), L"TEST RECOMMENDATIONS 1" );
myNotebook->AddPage( new wxNotebookPage( myNotebook, -1 ), L"TEST RECOMMENDATIONS 2" );
myNotebook->AddPage( new wxNotebookPage( myNotebook, -1 ), L"TEST RECOMMENDATIONS 3" );
myNotebook->AddPage( new wxNotebookPage( myNotebook, -1 ), L"TEST RECOMMENDATIONS 4" );
myNotebook->AddPage( new wxNotebookPage( myNotebook, -1 ), L"TEST RECOMMENDATIONS 5" );
myNotebook->AddPage( new wxNotebookPage( myNotebook, -1 ), L"TEST RECOMMENDATIONS 6" );
myNotebook->Layout();

Notebook Pages and Focus

If you wish to use widgets such as wxTextCtrl, choice, radiobutton, checkbox on your notebook pages, and if you wish to navigate easily among those widgets and the tabs, your notebook pages must be wxPanel and not wxWindow objects. wxWindow objects do not transfer the focus to their first child widget; while wxPanel pages do.

See Also