Martin Perry
Martin Perry

Reputation: 9527

wxNotebook - inner wxPanel - call method when page is changed

I have wxNotebook with several wxNotebookPage. Each page has a different content that inherits from wxPanel. What method from wxPanel is called when active page is changed? If I change panel, I would like to update panel content.

I have the similar functionality binded to resize event which is working.

void MyPanel::Init() {
     this->Bind(wxEVT_SIZE, &MyPanel::OnResize, this);
}

void MyPanel::OnResize(wxSizeEvent& ev){
    //do something to update panel
}

Note: This is C++ code, but the programming language is not important (it can be Python). I will update the solution, I just need the logic or wxWidget API calls that are same.

Upvotes: 0

Views: 280

Answers (1)

New Pagodi
New Pagodi

Reputation: 3554

What method from wxPanel is called when active page is changed?

There is no method called on the panel. Instead a page changed event is sent to the notebook control. You can set up a handler for this event similar to how you set up a handler for the size events on your panels above. Usually this is done in the constructor for your frame like so:

MyFrame::MyFrame(...):wxFrame(...)
{
...
    <notebookobject>->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED, &MyFrame::OnPageChanged, this);
...
}

...

void MyFrame::OnPageChanged(wxBookCtrlEvent& event)
{
    // do something in response to the page change here.
}

There is also a page changing event that is sent before the page is actually changed. The page changing event has an extra feature that if you want to disallow the page from being changed, you can call Veto() on the event object in the page changing handler.

Upvotes: 2

Related Questions