How to change the ClientRect of a form?

非 Y 不嫁゛ 提交于 2019-12-14 04:13:06

问题


Please refer to another question here: Resizing borderless form from different constraints than far edges?

This previous question has been resolved, but I have another similar question. Since I am building a custom shaped form with a different client area, I need to change the ClientRect area of this form. The form has some special drawing of some curved edges and such, but that part's irrelevant. I need to change the ClientRect of the form to represent a new client area where components are allowed to be dropped, and ignore anything put outside of those bounds.

(I have a borderless form, I'm drawing my own border which is a much different size than the standard windows border.)

This solution will kind-of change the way that my previous question works, but that'll be another topic which I'm sure I'll figure out on my own, should be very simple. I just need to be able to properly set this in the first place.


回答1:


type
  TForm1 = class(TForm)
    ..
  private
    procedure WmNCCalcSize(var Msg: TWMNCCalcSize); message WM_NCCALCSIZE;
    ..

..

procedure TForm1.WmNCCalcSize(var Msg: TWMNCCalcSize);
begin
  inherited;
  if Msg.CalcValidRects then begin
    InflateRect(Msg.CalcSize_Params.rgrc[0], -10, -6);
    Msg.Result := 0;
  end;
end;


Please, carefully read WM_NCCALCSIZE's documentation though, including the remarks section and also NCCALCSIZE_PARAMS, as I'm not sure this is what you want. But this is your message..



来源:https://stackoverflow.com/questions/8393516/how-to-change-the-clientrect-of-a-form

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!