Get children to detect parent event? Topic is solved

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
aquawicket
Earned some good credits
Earned some good credits
Posts: 103
Joined: Sun Aug 05, 2007 5:49 am

Get children to detect parent event?

Post by aquawicket »

I know this is probobly an easy one, but I didn't find much on it. I'm looking for the best method to get the children to detect the parents size.

i.e. Parent is resized, childern detect the parents resize and take action to resize themselves.
clyde729
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Mon May 29, 2006 10:50 pm
Location: Jena, Germany

Post by clyde729 »

The most cleanest solution is to use a wxSizer or rather a derivate of it. Define some flags on how the child should be resized and the framework will do the rest. There are samples on how to do it.
OS: Windows XP Home, Compiler: MingW, Version: wxWidgets 2.8.0, IDE: wx-Devcpp
framepointer
Super wx Problem Solver
Super wx Problem Solver
Posts: 264
Joined: Mon Aug 07, 2006 3:25 pm
Location: Baia Mare, Romania
Contact:

Post by framepointer »

It's a simple one :)

You can do it like this

Code: Select all

class wxMyChildWindow : public wxWindow
{
	public:
		wxMyChildWindow(wxWindow * pParent) : wxWindow(pParent)
		{
			Connect(pParent->GetId(), wxEVT_SIZE, wxSizeEventHandler(wxMyChildWindow::OnParentResize()), 0L, this );
		}

		void OnParentResize(wxSizeEvent & event)
		{
			// do something here
			// You can either use GetParent() and use GetSize() or similar methods
			// or you can use the properties of the event.
			// For more read the wxSizeEvent documentation :)
		}
};
Or, if it's not a custom component

Code: Select all

void MyClass::CreateTextCtrl(wxWindow * pParent)
	{
		// ... //
		wxTextCtrl * pTextCtrl = new wxTextCtrl(pParent, wxId_ANY, "");
		pTextCtrl->Connect(pParent->GetId(), wxEVT_SIZE, wxSizeEventHandler(MyClass::OnParentResize()), 0L, this);
	}

	void MyClass::OnParentResize(wxSizeEvent & event)
	{
		// ur code
	}
But if you are looking for ayout and stuff, try to use wxSizer. It does all the calculations and much more that is needed for a clean and neat layouyt.

Regards[/code]
Software is like sex,
It's better when it's free.
~Linus Torvalds
Post Reply