Search code examples
c++user-interfacewxwidgets

How do I get a widget by id in wxWidgets?


I'm quite new to C++ and wxWidgets.

wxTextCtrl* text = new wxTextCtrl(panel, SOME_ID);

My question is how to get that text control by its ID. I would like to change its value in a different scope. Do I need to keep a pointer to each widget that could have its state changed or is there a way to get that pointer from its ID?

This is probably an easy question, but I guess I couldn't find the correct search terms to find an answer.


Solution

  • You probably want the static function wxWindow::FindWindowById. It returns a plain wxWindow pointer so you will have to cast it to a wxTextCtrl pointer for your example.