Hi,
this is probably a very silly question but I can't figure out. I'm new to wxWidgets and have understood how events work. Now I want to access a wxTextCtrl from my main frame class. The object ist placed in an other class like wxPanel -> wxNotebook -> wxPanel(as notebook page) -> wxTextCtrl. Any help is very appreciated
Regards Apoc
Access controls in child wxPanel Topic is solved
Hi,
Three approaches. If you are the one creating the controls, store them as a member variable in your class like;
Or you could use FindWindowById, where you give the ID of the window and get a wxWindow pointer back. This can be (dynamically) casted to wxButton or any control you like, but has a potential hazard in the fact you can mis-cast the control, or the cast can return 0.
See
http://www.wxwidgets.org/manuals/2.6.3/ ... windowbyid
The last method is iterating over the wxPanel which will return all the wxWindow * elements on that panel. Only useful when you do not know what is on the wxPanel and you need to scan for the controls.
Regards,
- Jorgen
Three approaches. If you are the one creating the controls, store them as a member variable in your class like;
Code: Select all
class MyFrame : public wxFrame
{
private:
m_button *wxButton;
};
// and further down the road at creation:
m_button = new wxButton(...);
See
http://www.wxwidgets.org/manuals/2.6.3/ ... windowbyid
The last method is iterating over the wxPanel which will return all the wxWindow * elements on that panel. Only useful when you do not know what is on the wxPanel and you need to scan for the controls.
Regards,
- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
Hi Jorg, thanks for the input!
I was playing arround with FindWindowById but didn't have in mind that wxTextCtrl is derived from wxWindow. Now I have a working solution. Is this the way to go or is there a better one?
Regards Apoc
I was playing arround with FindWindowById but didn't have in mind that wxTextCtrl is derived from wxWindow. Now I have a working solution. Is this the way to go or is there a better one?
Code: Select all
wxTextCtrl* myTC;
myTC = (wxTextCtrl*)this->FindWindowById(ID_MySQLADDRESS);
wxMessageBox(myTC->GetValue());
-
- Knows some wx things
- Posts: 26
- Joined: Tue Nov 14, 2006 1:51 pm
- Location: Duesseldorf, Germany
You should use a C++ style cast:
Code: Select all
wxTextCtrl* myTC = static_cast< wxTextCtrl* >(FindWindowById(ID_MySQLADDRESS)); // if you are _absolutely_ sure that FindWindowById(ID_MySQLADDRESS) will return a wxTextCtrl*
if (myTC == 0) { /* nope, this control was not found */ }
// or
wxTextCtrl* myTC = dynamic_cast< wxTextCtrl* >(FindWindowById(ID_MySQLADDRESS));
if (myTC == 0) { /* nope, this control was either not found or not a text control */ }