access wxStaticText object created in a different class

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
jbird80
In need of some credit
In need of some credit
Posts: 2
Joined: Mon May 12, 2008 12:47 am
Location: Maryland
Contact:

access wxStaticText object created in a different class

Post by jbird80 » Wed Jul 22, 2009 12:51 pm

I have a wxstaticText object on the main wxframe called oMainFrame. within oMainFram is a wxNotebook i popluate with wxPanels. my problem is within on of the wxPanels I have a spiner that when the value changes i need to change the text on oMainFrame but cant seem to get access to the wxStaticText component on oMainFrame. i've tried just including the "CMainFrame.h" that causes errors. any sugestions would be greatly appreciated.
Jason Bird

spectrum
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Sat Jul 21, 2007 12:17 pm

Post by spectrum » Wed Jul 22, 2009 1:01 pm

hello jbird,

since all the childs controls have mainframe as parent, you should be able to use wxWidgets event system.
Study on
http://docs.wxwidgets.org/2.8/wx_eventh ... ngoverview

Another way is to use wxEvtHandler::Connect, and connect the spin event to a mainframe method.

regards,
spectrum

jbird80
In need of some credit
In need of some credit
Posts: 2
Joined: Mon May 12, 2008 12:47 am
Location: Maryland
Contact:

Post by jbird80 » Wed Jul 22, 2009 4:19 pm

but how when the spin control event is a member of the wxPanel and the wxStaticText is a member of the oMainFram.

for example (this is not completete code just a outline)

Code: Select all

//oMainFrain.h
class CMainFrame: public wxFrame
{
   public:
   

   SetLabel(wxString str);

   private:
   
   wxStaticText* oMainFrame_StaticText;
   wxNotebook* oNotebook;
   wxSpinCtrl* oMainFrame_SpinCtrl;

   protected:

   CPage* oPage;
};

Code: Select all

//oMainFraim.cpp

CMainFram::On_oMainFrame_SpinCtrl()
{
  if(oMainFrame_SpinCtrl == somevalue)
  {
     oPage = new CPage;
     oNoteBook->AddPage(oPage)
  }
}

Code: Select all

//CPage.h
class CPage: public wxPanel
{
  public:
  void onSpinCtrl();
  wxSpinCtrl* oPage_SpinCtrl;
}
//CPage.cpp

Code: Select all

void CPage::onSpinCtrl();
{
   //Do some calculations
   
   //Here is where i'm trying to change the value of the MainFrame static Text.
   CMainFrame->SetLabel();
}
Jason Bird

Post Reply