+// MyAutoScrollWindow
+
+const long ID_RESIZEBUTTON = wxNewId();
+const wxSize SMALL_BUTTON( 100, 50 );
+const wxSize LARGE_BUTTON( 300, 100 );
+
+BEGIN_EVENT_TABLE( MyAutoScrollWindow, wxScrolledWindow)
+ EVT_BUTTON( ID_RESIZEBUTTON, MyAutoScrollWindow::OnResizeClick)
+END_EVENT_TABLE()
+
+MyAutoScrollWindow::MyAutoScrollWindow( wxWindow *parent )
+ : wxScrolledWindow( parent )
+{
+ SetBackgroundColour( wxT("GREEN") );
+
+ // Set the rate we'd like for scrolling.
+
+ SetScrollRate( 5, 5 );
+
+ // Populate a sizer with a 'resizing' button and some
+ // other static decoration
+
+ wxFlexGridSizer *innersizer = new wxFlexGridSizer( 2, 2 );
+
+ m_button = new wxButton( this,
+ ID_RESIZEBUTTON,
+ _T("Press me"),
+ wxDefaultPosition,
+ SMALL_BUTTON );
+
+ // We need to do this here, because wxADJUST_MINSIZE below
+ // will cause the initial size to be ignored for Best/Min size.
+ // It would be nice to fix the sizers to handle this a little
+ // more cleanly.
+
+ m_button->SetSizeHints( SMALL_BUTTON.GetWidth(), SMALL_BUTTON.GetHeight() );
+
+ innersizer->Add( m_button,
+ 0,
+ wxALIGN_CENTER | wxALL | wxADJUST_MINSIZE,
+ 20 );
+
+ innersizer->Add( new wxStaticText( this, -1, _T("This is just") ),
+ 0,
+ wxALIGN_CENTER );
+
+ innersizer->Add( new wxStaticText( this, -1, _T("some decoration") ),
+ 0,
+ wxALIGN_CENTER );
+
+ innersizer->Add( new wxStaticText( this, -1, _T("for you to scroll...") ),
+ 0,
+ wxALIGN_CENTER );
+
+ // Then use the sizer to set the scrolled region size.
+
+ SetSizer( innersizer );
+}
+
+void MyAutoScrollWindow::OnResizeClick( wxCommandEvent &WXUNUSED( event ) )
+{
+ // Arbitrarily resize the button to change the minimum size of
+ // the (scrolled) sizer.
+
+ if( m_button->GetSize() == SMALL_BUTTON )
+ m_button->SetSizeHints( LARGE_BUTTON.GetWidth(), LARGE_BUTTON.GetHeight() );
+ else
+ m_button->SetSizeHints( SMALL_BUTTON.GetWidth(), SMALL_BUTTON.GetHeight() );
+
+ // Force update layout and scrollbars, since nothing we do here
+ // necessarily generates a size event which would do it for us.
+
+ FitInside();
+}
+