Programming => LCL => Topic started by: Warfley on July 18, 2020, 01:01:40 pm

Title: WinControl reserved Space
Post by: Warfley on July 18, 2020, 01:01:40 pm
Hey, I've just gotten curious about something.

Components like groupboxes have reserved space, in the case of the groupbox there is a header contining the caption. Positioning a Button on Location (0, 0) positions it right under the header, increasing the font size increases the header size.

So my question is now, when creating my own component, how can I reserve space like that, i.e. have an offset in child positioning (and also, but this is secondary, have the controls slide "under" the header, i.e. they disappear when getting negative coordinates)
Title: Re: WinControl reserved Space
Post by: jamie on July 18, 2020, 02:44:03 pm
U r most likely talking about the non client area. ?

U can create the window with non client borders by changing the values in the createparams

You override that to modify the window style before its created.
Title: Re: WinControl reserved Space
Post by: Warfley on July 18, 2020, 04:16:51 pm
Any example for this?
Title: Re: WinControl reserved Space
Post by: jamie on July 18, 2020, 05:54:16 pm
Here is a quick hack for a control with the thick border and a title bar that you can be moved around in the parent form.

 Not exactly sure what you are looking for but maybe the same as a Tgroupbox ? If that is being the case then you can use two controls , one as the master which can draw the border line and place your caption anywhere you wish, then the child of that control can be your client content. This way you can get two different set of events, one for the border and one for the smaller area..

 Anyways, clipped here is an example of overriding the CreateParams, this gives you something interesting, at least on windows it does. I assume it should work on other targets too, I didn't use anything special other than the LCLType and LCLIntf.
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  3. {$mode objfpc}{$H+}
  5. interface
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs,LCLType, LCLintF,Windows;
  10. type
  11.  TMyControl = Class(TCustomControl)
  12.    Procedure Createparams(var params:TCreateparams); Override;
  13.  end;
  15.   { TForm1 }
  17.   TForm1 = class(TForm)
  18.     procedure FormCreate(Sender: TObject);
  19.   private
  21.   public
  22.     AControl:TMyControl;
  24.   end;
  26. var
  27.   Form1: TForm1;
  29. implementation
  31. {$R *.lfm}
  33. { TForm1 }
  35. procedure TForm1.FormCreate(Sender: TObject);
  36. begin
  37.  AControl := TMyControl.Create(Self);
  38.  Acontrol.Parent := Self;
  39.  AControl.Width := 100;
  40.  ACOntrol.Height:= 100;
  41.  Acontrol.Caption :='Something';
  42.  Acontrol.Visible:=true;
  43. end;
  45. Procedure TMyControl.Createparams(var params:TCreateparams);
  46. Begin
  47.   Inherited;
  48.   params.Style := params.Style or WS_CAPTION;
  49.   Params.ExStyle := Params.Exstyle or WS_EX_OVERLAPPEDWINDOW;
  50. end;
  52. end.
Title: Re: WinControl reserved Space
Post by: MarkMLl on July 18, 2020, 06:09:26 pm
Watch out for the case where groupboxes take a different amount of space depending on whether the caption is blank or not.

ISTM that Autosizing a form is the complement of fitting a control into the available client space.

Title: Re: WinControl reserved Space
Post by: jamie on July 18, 2020, 07:05:38 pm
a single window can be used for this if he wants to handle all of it in the WM_BEGINPAINT
 First the outside border may need updating and then a region can be placed within the DC context to that everything relative to some port of the control. That basically would behave like a client area.

TinyPortal © 2005-2018