开发者

How do I stop a form from exceeding the window height?

开发者 https://www.devze.com 2023-02-21 22:17 出处:网络
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).

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消