Control resizing itself

Joost imim at newhouse.nl
Wed Aug 2 01:27:50 PDT 2006


Joost wrote:
> I've implemented DoGetBestSize() to return the optimum size. Initially 
> this works fine, upon startup my control is made the right size.
> 
> But then something happens which require the control to enlarge itself. 
> How should the control notify the sizer hierarchy that its best size has 
> changed?

Ok, found the solution. Part of the problem was the fact that my control 
was on a wxNotebook page that was invisible during the resize. Therefore 
Frame->Layout() did not work, it only layouts the visible notebook page.

With the below code I got it working. Thanks Vadim and Armel for your help.

Joost



void MyControl::AfterBestSizeChange()
{
   // InvalidateBestSize() recursively invalidates the best
   // size of the parent sizers too:
   InvalidateBestSize();
   // Find the topmost window in the hierarchy:
   wxWindow *topwindow=this;
   while(true)
   {
     if(!GetParent()) break;
     topwindow=topwindow->GetParent();
     if(topwindow->IsKindOf(CLASSINFO(wxTopLevelWindow)))
     {
       // stop at the Frame:
       break;
     }
     if(!topwindow->IsShown())
     {
       // stop at invisible window (e.g. hidden wxNotebook page)
       break;
     }
   }
   topwindow->Layout();
}





More information about the wx-users mailing list