Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Positioning TSplitter at runtime 1

Status
Not open for further replies.

bledazemi

Programmer
Jul 14, 2005
93
GB
Hi All,

Can someone help me. I am trying to create a number of Panels inside a scrollbox. Between each panel i need a splitter. I have written following code to achieve this.
When i run this code all the splitters are displayed at the top of the ScrollBox. I would like each splitter to be in between two panels created.

Could someone tell me what am i doing wrong?

Thank you very much in advance

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,Controls, Forms, Dialogs, ExtCtrls;

type
TForm1 = class(TForm)
ScrollBox1: TScrollBox;
procedure FormCreate(Sender: TObject);

end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
panel:TPanel;
splitter:TSplitter;
x,i:integer;
begin
x:=10;
//Create x number of panels inside ScrollBox1 aligned on top
for i:=1 to x do
begin
//Create the panel and align it on top
panel:=TPanel.Create(ScrollBox1);
panel.Parent:=ScrollBox1;
panel.Align:=alTop;

//Add a splitter and align it on top (below the panel just created???)
splitter:=TSplitter.Create(ScrollBox1);
splitter.Parent:=ScrollBox1;
splitter.Align:=alTop;
end;

//Add one final panel aligned as client
panel:=TPanel.Create(ScrollBox1);
panel.Align:=alClient;
end;
 
Hi,

I found out the solution to my question. It appears that simply aligning controls one after the other does not necessarily align them in order.

It appears that position of each control must be explicitly set in order to make sure that controls are aligned in desired order.

Just in case someone else encounters with the same question here is how i managed to split my runtime panels with runtime splitters.

Happy programming to all :).



type
TForm1 = class(TForm)
ScrollBox1: TScrollBox;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
panel:TPanel;
splitter:TSplitter;
x,i,nTop:integer;
begin
x:=10;
nTop:=0;
//Create x number of panels inside ScrollBox1 aligned on top
for i:=1 to x do
begin
//Create the panel and align it on top
panel:=TPanel.Create(ScrollBox1);
panel.Parent:=ScrollBox1;
panel.Caption:=Format('Panel %d',);
panel.Align:=alTop;
panel.Top:=nTop;
panel.Height:=40;
inc(nTop,40);

//Add a splitter and align it on top (below the panel just created???)
splitter:=TSplitter.Create(ScrollBox1);
splitter.Parent:=ScrollBox1;
splitter.Align:=alTop;
splitter.Top:=panel.Top+panel.Height;
end;

//Add one final panel aligned as client
panel:=TPanel.Create(ScrollBox1);
panel.Align:=alClient;
panel.Caption:='Client panel';
panel.Parent:=ScrollBox1;
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top