Recent

Author Topic: WinControl reserved Space  (Read 432 times)

Warfley

  • Sr. Member
  • ****
  • Posts: 311
WinControl reserved Space
« 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)

jamie

  • Hero Member
  • *****
  • Posts: 3648
Re: WinControl reserved Space
« Reply #1 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.
The only true wisdom is knowing you know nothing

Warfley

  • Sr. Member
  • ****
  • Posts: 311
Re: WinControl reserved Space
« Reply #2 on: July 18, 2020, 04:16:51 pm »
Any example for this?

jamie

  • Hero Member
  • *****
  • Posts: 3648
Re: WinControl reserved Space
« Reply #3 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;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs,LCLType, LCLintF,Windows;
  9.  
  10. type
  11.  TMyControl = Class(TCustomControl)
  12.    Procedure Createparams(var params:TCreateparams); Override;
  13.  end;
  14.  
  15.   { TForm1 }
  16.  
  17.   TForm1 = class(TForm)
  18.     procedure FormCreate(Sender: TObject);
  19.   private
  20.  
  21.   public
  22.     AControl:TMyControl;
  23.  
  24.   end;
  25.  
  26. var
  27.   Form1: TForm1;
  28.  
  29. implementation
  30.  
  31. {$R *.lfm}
  32.  
  33. { TForm1 }
  34.  
  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;
  44.  
  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;
  51.  
  52. end.
  53.  
  54.  
The only true wisdom is knowing you know nothing

MarkMLl

  • Hero Member
  • *****
  • Posts: 1330
Re: WinControl reserved Space
« Reply #4 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.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

jamie

  • Hero Member
  • *****
  • Posts: 3648
Re: WinControl reserved Space
« Reply #5 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
call..
 
 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.

The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018