1

My form exceeds the window's height (when I use the splitter which changes a panel's height which in turn changes the form's size).

How can I stop it from resizing like that?

Dian
  • 1,187
  • 3
  • 18
  • 35
  • If the form "grows down", play with the minsize, the position and the alignment of the splitter. The VCL can get things wrong and resize a form when resizing and realigning its contained controls and splitters with minsizes are involved. See: http://stackoverflow.com/questions/4835617/how-do-i-avoid-this-unwanted-behaviour-with-delphis-tsplitter-and-panels for more information on this. – Marjan Venema Apr 05 '11 at 10:22
  • You want to "stop it resizing like that"? You want to stop users from exceeding a certain size, or you want to prevent code that you wrote that changes the height from changing that height? I have never seen a splitter INSIDE a form change the outside form's height. So obviously you're doing something weird already in your code. – Warren P Apr 05 '11 at 15:42

1 Answers1

3

I assume you're changing the form size yourself, because I can't find a way to make the splitter do that automatically. You can get the Height of the screen using the Screen object in the Forms unit. You can simply test against Screen.Height or, if you want to better support multiple monitors, test against Screen.MonitorFromWindow(Handle).Height

Code sample, untested, should get you started:

var MaxFormHeight: Integer;
    NewFormHeight: Integer;
    M: TMonitor;
begin
  // Get the monitor that's hosting the form
  M := M := Screen.MonitorFromWindow(Handle);     
  MaxFormHeight := M.WorkAreaRect.Bottom - M.WorkAreaRect.Top - Top; // Take into account actual available monitor space and the Top of the window
  // Do your stuff to calculate NewFormHeight
  if NewFormHeight > MaxFormHeight then
    NewFormHeight := MaxFormHeight;
  Height := NewFormHeight;
end;
Cosmin Prund
  • 25,498
  • 2
  • 60
  • 104