views:

660

answers:

4

This is the hierarchy of widgets I've got:

Frame > wxBoxSizer > wxPanel > wxBoxSizer > wxFlexGridSizer (2 columns, 9 rows), with assorted form fields and buttons inside.

The first BoxSizer is to place the panel in, and the second is to make a border around the FlexGrid.

Everything looks nice, and the frame can expand properly if the window is enlarged, but it also can be resized to almost nothing, hiding all form elements.

How do I force the minimum size for the window to the one suggested by the FlexGridSizer by default (all form elements visible and having their minimal possible sizes)?

+1  A: 

I would try calling wxFrame->SetMinSize(wxSize) with whatever wxFlexGridSizer->GetMinSize() returns, should work, but not tested. You will need to note what GetMinSize says about coverting to window size before passing it I expect.

SteveL
+2  A: 

Using the SetMinSize() method on your Frame to set a minimum size will set a limit on the smallest area of the frame (just tested it). Once set, wxWidgets will not allow the frame to be sized smaller than the value specified.

I'd set the value like this. In the constructor, set up all the elements of the frame. At the end, after you call the Layout() method to setup all the sizers and such, call the GetSize(int *w, int *h) method to get the x and y size of your frame at the default layout. Use those values to call the SetMinSize() method to set that default size as the minimum for your Frame. This will take into account all the various padding and borders and such set up by the frame and the contained elements.

dagorym
A: 

In wxPerl, dagorym's answer can be written concisely as $self->SetMinSize($self->GetSize()); after a call to Layout().

MaxVT
A: 

Probably much too late but the answers given here are needlessly complicated, you just need to call SetSizerAndFit(sizer) to both associate the sizer with the frame, set its initial size and also set this size as minimal acceptable size.

VZ