Search code examples
delphidelphi-7

How to change the ClientRect of a form?


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.


Solution

  • 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..