Recent

Author Topic: Programmatically adding controls to TPanel hides its bevel  (Read 2377 times)

Superdisk

  • Jr. Member
  • **
  • Posts: 73
Programmatically adding controls to TPanel hides its bevel
« on: June 06, 2021, 08:51:27 pm »
I have a TPanel, and I'm trying to add a custom control to it by setting the control's Parent property to the TPanel.

Unfortunately, it looks like the attached image. As you can see, the bevel is hidden underneath the control itself-- it's like the control is taking up more than the client area of the panel. If I add a control using the IDE (not programmatically) and set the Align to alClient, you can see that it takes up the correct amount of space.

How do I fix this?

jamie

  • Hero Member
  • *****
  • Posts: 6131
Re: Programmatically adding controls to TPanel hides its bevel
« Reply #1 on: June 06, 2021, 09:25:49 pm »
The bevel is part of the client area of the panel.. its not a separate border component..

You need to offset your child controls to the width of the bevel.

 you could waste some resources by putting a panel inside another panel then shrink the inner panel using the anchor editor and then apply the child controls to the inner panel

 also there is Child sizing in the panel that suppose to help you in this cause.

The only true wisdom is knowing you know nothing

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Programmatically adding controls to TPanel hides its bevel
« Reply #2 on: June 06, 2021, 10:01:43 pm »
I don't think jamie is correct.

This code
Code: Pascal  [Select][+][-]
  1. type
  2.  
  3.   TMyControl = class(TCustomControl)
  4.   end;
  5.  
  6.   TForm1 = class(TForm)
  7.     Panel: TPanel;
  8.     procedure FormCreate(Sender: TObject);
  9.   private
  10.     FMyControl: TMyControl;
  11.   end;
  12.  
  13. var
  14.   Form1: TForm1;
  15.  
  16. implementation
  17.  
  18. procedure TForm1.FormCreate(Sender: TObject);
  19. begin
  20.   Color := clSilver;
  21.   panel.BevelWidth := 10;
  22.   FMyControl := TMyControl.Create(Self);
  23.   FMyControl.Align := alClient;
  24.   FMyControl.Color := clSkyBlue;
  25.   FMyControl.Parent := Panel;
  26. end;

gives the attached screenshot.

jamie

  • Hero Member
  • *****
  • Posts: 6131
Re: Programmatically adding controls to TPanel hides its bevel
« Reply #3 on: June 06, 2021, 11:24:22 pm »
Drop a control on it from the OI.. Like a TBUTTON or TEDIT..

You can place that anywhere in that panel, including over the bevel.

and yes, using the Client align fixes that but how about when you don't want that ?

Without alignment the LCL allows it to hang over the bevel so its not 100% fool proof but one can simply anchor so it does not matter.

Also note that when doing so the LEFT,TOP of the control is no longer 0,0 but where the bevel ends off.


« Last Edit: June 06, 2021, 11:29:23 pm by jamie »
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018