I am having issue with panels created once scrolling is needed the width is too wide. I was having another issue with placement incorrect, but I fixed that issue already.
There also another issue when resizing the form messes up to the position of panels.
unit Unit8;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.UITypes,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ToolWin, Vcl.ComCtrls,
Vcl.ExtCtrls;
type
TForm8 = class(TForm)
ScrollBox1: TScrollBox;
ToolBar1: TToolBar;
Button3: TButton;
Button4: TButton;
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form8: TForm8;
implementation
{$R *.dfm}
var
ScrollBox: TScrollBox;
function GetInScrollBoxTopPos: integer;
var
I: integer;
begin
result := 0;
for I := 0 to ScrollBox.ControlCount - 2 do
if ScrollBox.Controls[I] is TPanel then
result := result + TPanel(ScrollBox.Controls[I]).Height + 5;
end;
type
TPanel160 = class
panel: TPanel;
constructor Create(AOwner: TComponent);
end;
type
TPanel40 = class
panel: TPanel;
constructor Create(AOwner: TComponent);
end;
procedure TForm8.Button3Click(Sender: TObject);
var
panel : TPanel160;
begin
panel := TPanel160.Create(self)
end;
{ TPanel160 }
constructor TPanel160.Create(AOwner: TComponent);
begin
panel := TPanel.Create(AOwner);
panel.Parent := ScrollBox;
panel.Color := TColorRec.Red;
panel.Caption := '';
panel.Height := 160;
panel.Width := ScrollBox.Width - 20;
panel.Top := GetInScrollBoxTopPos;
panel.Left := 10;
panel.Anchors := [akLeft, akRight];
end;
{ TPanel40 }
constructor TPanel40.Create(AOwner: TComponent);
begin
panel := TPanel.Create(AOwner);
panel.Parent := ScrollBox;
panel.Color := TColorRec.Blue;
panel.Caption := '';
panel.Height := 40;
panel.Width := ScrollBox.Width - 20;
panel.Top := GetInScrollBoxTopPos;
panel.Left := 10;
panel.Anchors := [akLeft, akRight];
end;
procedure TForm8.Button4Click(Sender: TObject);
var
panel : TPanel40;
begin
panel := TPanel40.Create(self)
end;
procedure TForm8.FormCreate(Sender: TObject);
begin
ScrollBox := ScrollBox1
end;
end.
copy.zip