Resize wxScrolledWindow to 60% of screen width/height

Volker Bartheld dr_versaeg at freenet.de
Mon Oct 1 05:39:43 PDT 2007


Hi!

I don't want my wxScrolledWindow to grow larger than 60% of the screen
width/height but show a scrollbar instead. I have found that if you initially
m_ScrolledWin->SetScrollRate(10, 10);
and then just m_ScrolledWin->SetSize(0.6*screenWidth, -1);
also a vertical scrollbar shows up, even if I call Fit() and/or Layout()
on the wxDialog that contains a sizer and m_ScrolledWin within.

So I came up with the following solution:

void MyDialog::OnIdleOnce(wxIdleEvent&)
{
  int virtualWidth, virtualHeight;
  m_ScrolledWin->GetVirtualSize(&virtualWidth, &virtualHeight);
  int screenWidth  = wxSystemSettings::GetMetric(wxSYS_SCREEN_X);
  int screenHeight = wxSystemSettings::GetMetric(wxSYS_SCREEN_Y);
  if(virtualWidth>0.6*screenWidth && virtualHeight>0.6*screenHeight)
  {
    m_ScrolledWin->SetSize(0.6*screenWidth, 0.6*screenHeight);
    m_ScrolledWin->SetScrollRate(10, 10);
  }
  else if(virtualWidth>0.6*screenWidth)
  {
    m_ScrolledWin->SetSize(0.6*screenWidth, -1);
    m_ScrolledWin->SetScrollRate(10, 0);
  }
  else if(virtualHeight>0.6*screenHeight)
  {
    m_ScrolledWin->SetSize(-1, 0.6*screenHeight);
    m_ScrolledWin->SetScrollRate(0, 10);
  }
  else m_ScrolledWin->SetScrollRate(0, 0);
  Fit();
}

that suppresses either the horizontal or the vertical scrollbar or both if
not necessary in a handler that is called once (and only once) if the system
is idle after rendering the Dialog. This seems to work as planned but looks
pretty clumsy. Is there a better solution (portable to wxMSW/wxUnix) to shrink
a scrolled window and show a scrollbar appropriately?

Thanks a lot in advance,
Volker

-- 
mailto:  V B A R T H E L D at G M X dot D E






More information about the wx-users mailing list