* * *

Author Topic: If aligned inside container, internal height doesn't change  (Read 1144 times)

bdexterholland

  • Jr. Member
  • **
  • Posts: 56
  • uh?
If aligned inside container, internal height doesn't change
« on: January 12, 2018, 10:17:03 pm »
i have a situation that combines TPanel & TSpeedButtons.

If I drop TSpeedButtons inside TPanel and use this code to resize TSpeedButton, why not TSpeedbutton changes internal's height since it visuality it will be different?
Code: Pascal  [Select]
  1.   TPanel.BorderWidth: = 10;
  2.   TPanel.Height := 50;
  3.   TSpeedButton.Align := Alright;
  4.   TSpeedButton.Width := TSpeedButton.Height;

This behavior repeats with TButton and TBitbtn
« Last Edit: January 12, 2018, 10:20:01 pm by bdexterholland »
[sleep .....]

ASerge

  • Hero Member
  • *****
  • Posts: 705
Re: If aligned inside container, internal height doesn't change
« Reply #1 on: January 12, 2018, 10:32:54 pm »
Code: Pascal  [Select]
  1.   TPanel.BorderWidth: = 10;
  2.   TPanel.Height := 50;
  3.   TSpeedButton.Align := Alright;
  4.   TSpeedButton.Width := TSpeedButton.Height;
Executed as expected - SpeedButton is located over the entire height of the Panel, taking into account, of course, Panel.BorderWidth.

howardpc

  • Hero Member
  • *****
  • Posts: 2647
Re: If aligned inside container, internal height doesn't change
« Reply #2 on: January 12, 2018, 10:40:24 pm »
?? That code does not even compile, using type names (TPanel) instead of instance names (Panel1 or whatever).

bdexterholland

  • Jr. Member
  • **
  • Posts: 56
  • uh?
Re: If aligned inside container, internal height doesn't change
« Reply #3 on: January 12, 2018, 10:42:30 pm »
?? That code does not even compile, using type names (TPanel) instead of instance names (Panel1 or whatever).

I Know man, that`s not the point....
[sleep .....]

bdexterholland

  • Jr. Member
  • **
  • Posts: 56
  • uh?
Re: If aligned inside container, internal height doesn't change
« Reply #4 on: January 12, 2018, 10:45:53 pm »
Executed as expected - SpeedButton is located over the entire height of the Panel, taking into account, of course, Panel.BorderWidth.
I'm not sure if i got what you said. Think about TSpeedbutton.Parent = TPanel.

In this case, Tpanel.ClientHeight = 30 and, by some reason, you set in object inspector TSpeedButton.Height = 50 and align it to alRight (even alLeft) inside TPanel, should not TSpeedButton.Height be changed to 30 by new align?
[sleep .....]

ASerge

  • Hero Member
  • *****
  • Posts: 705
Re: If aligned inside container, internal height doesn't change
« Reply #5 on: January 12, 2018, 10:56:22 pm »
should not TSpeedButton.Height be changed to 30 by new align?
So it is, more precisely become 28, taking into account Panel.BevelWidth.

howardpc

  • Hero Member
  • *****
  • Posts: 2647
Re: If aligned inside container, internal height doesn't change
« Reply #6 on: January 12, 2018, 11:10:48 pm »
I think you may be best to do this in two stages, since setting Align does not directly set Height (LCL bounds setting may be deferred).

In a new Lazarus project drop a panel on the main form, and complete it as follows. Does this give the general effect you want?
Code: Pascal  [Select]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Forms, sysutils, Controls, ExtCtrls, Buttons;
  9.  
  10. const
  11.   Speed_Button_Count = 5; // set to desired value
  12.  
  13. type
  14.  
  15.   TForm1 = class(TForm)
  16.     Panel1: TPanel;
  17.     procedure FormCreate(Sender: TObject);
  18.     procedure FormShow(Sender: TObject);
  19.   private
  20.     sbArray: array of TSpeedButton;
  21.     procedure CreateButtons(aButtonCount: Integer; aPanelParent: TPanel);
  22.     procedure SpeedbuttonClick(Sender: TObject);
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.  
  28. implementation
  29.  
  30. {$R *.lfm}
  31.  
  32. procedure TForm1.CreateButtons(aButtonCount: Integer; aPanelParent: TPanel);
  33. var
  34.   i: Integer;
  35. begin
  36.   SetLength(sbArray, aButtonCount);
  37.   for i := 0 to aButtonCount-1 do begin
  38.     sbArray[i]:=TSpeedButton.Create(aPanelParent);
  39.     with sbArray[i] do begin
  40.       Caption:=IntToStr(i+1);
  41.       Name:='SpeedButton' + IntToStr(i+1);
  42.       Align:=alRight;
  43.       BorderSpacing.Around:=5;
  44.       OnClick:=@SpeedbuttonClick;
  45.       Parent:=aPanelParent;
  46.     end;
  47.   end;
  48. end;
  49.  
  50. procedure TForm1.FormCreate(Sender: TObject);
  51. begin
  52.   Panel1.BorderWidth := 5;
  53.   Panel1.Height := 55;
  54.   Panel1.Caption:='';
  55.   CreateButtons(Speed_Button_Count, Panel1);
  56. end;
  57.  
  58. procedure TForm1.FormShow(Sender: TObject);
  59. var
  60.   sb: TSpeedButton;
  61. begin
  62.   for sb in sbArray do
  63.     sb.Width:=sb.Height;
  64.   Panel1.Width:=Speed_Button_Count*(sb.Height + 5) + 15;
  65. end;
  66.  
  67. procedure TForm1.SpeedbuttonClick(Sender: TObject);
  68. begin
  69.   Caption:=Format('You clicked %s',[(Sender as TSpeedButton).Name]);
  70. end;
  71.  
  72. end.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus