I have a frame that has some stuff at the top, and a wxScrolledWindow below. The scrolled window contains an image selected by the user. I want the frame to shrink-wrap it so that background never shows in the scrolled window. I am using a BoxSizer in the frame. Everything works perfectly until the user drags a border to increase the viewing area. He takes it too far, and background shows. I have tried at least a dozen methods, but I cannot get the window's border to snap back when the user drags the border beyond where the scrollbars disappear. When the image is loaded, the scrolled window calls SetMaxClientSize() with the right numbers, but it has no effect. A couple of pictures will help. I have just dragged the right border to the right, increasing the viewing area. Here is what it looks like:
I want the border to snap back so it looks like this:
Windows 7 x64, wxWidgets 2.9.4
Re-implement the size event handler. If the new size is larger than you want, modify it to the largest you accept. Then call the base implementation.
void MyFrame::OnSize(wxSizeEvent& event)
{
wxSize new_size = event.GetSize()
wxSize max_size = ... calculate max size ....
if ( new_size.GetHeight() > max_size.GetHeight() {
new_size.SetHeight( max_size.GetHeight() );
if ( new_size.GetWidth() > max_size.GetWidth() {
new_size.SetWidth( max_size.GetWidth() );
event.SetSize( new_size );
wxFrame::OnSize( event );
Also, be aware of this note in the documentation:
Important : Sizers ( see Sizers Overview ) rely on size events to function correctly. Therefore, in a sizer-based layout, do not forget to call Skip on all size events you catch (and don't catch size events at all when you don't need to).