views:

260

answers:

2

I need to be able to programmatically add and remove tabs on a wxNotebook by the text/label that is displayed on each tab.

In windows, using a tab control and tab pages, I would be able to reference each tab by a key. The tab control has a map of tab pages keyed on the text of each tab. I'm trying to write some helper methods to recreate this feature, but am having difficulty.

+1  A: 

Have a look at the wxNoteBook api

Functions like GetPage will return a wxPanel pointer and the function SetPageText will allowing you to change the title and also functions like AddPage and DeletePage will allow you to dynamically change the pages.

Lodle
You didn't answer the question. I've read the API and DeletePage only accepts an integer value. GetPage only returns the currently selected page. What if I wanted to delete a page that the user hasn't selected?
Chris Andrews
I was wrong about GetPage it does take the page index.
Chris Andrews
Find the index for the page you want and then delete it?
Lodle
A: 

Use the following helper method to convert from the tab label/text to the corresponding index of the wxNotebookPage. After you have the index of the wxNotebookPage, then you can use all of the wxNotebook's methods that expect the page index as an argument.

int TabTestFrame::GetIndexForPageName( wxString tabText) {

 int end = Notebook1->GetPageCount();

 wxString selectedtabText = "";

 for ( int i = 0; i < end; i++)
 {

    selectedtabText = Notebook1->GetPageText(i);

    if (tabText == selectedtabText)
        return i;

 }

 return -1;

}

Chris Andrews