How do I stop a form from exceeding the window height?
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 t开发者_开发知识库hat?
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;
精彩评论