Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: resize controls beyond parent's client area



Permlink Replies: 6 - Last Post: Sep 14, 2015 11:37 AM Last Post By: Peter Below
Thomas Amaddeo

Posts: 3
Registered: 10/13/15
resize controls beyond parent's client area
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 13, 2015 12:50 AM
I'm trying to replicate what is done by MS SQL Managment Studio like asked in [here|http://stackoverflow.com/questions/13909756/how-to-resize-controls-beyond-parents-client-area]

Is there anyone that can help me solving this headache???

I have a ScrollBox, and in there, i create as many panels/splitters as i need based on the number of query executed.

Here is just a try, but i can't make it work as i want. once panels have reached the client area, i'm not able to resize them any bigger that the main form client area.

unit Unit1;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;

type
tDataBlock = class(TComponent)
fPanel: TPanel;
fLabel: TLabel;
fSplitter: TSplitter;
fOwner: TWinControl;

published
property Panel: TPanel read fPanel write fPanel;
property Text: TLabel read fLabel write fLabel;
property Owner: TWinControl read fOwner write fOwner;
public
constructor Create(Owner: TWinControl; var t: integer);
end;

TForm1 = class(TForm)
ScrollBox1: TScrollBox;
Button1: TButton;
Panel1: TPanel;
FlowPanel1: TFlowPanel;
procedure Button1Click(Sender: TObject);
private
BlockCount: integer;
procedure ConfigureScreen;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ConfigureScreen;
var i: integer;
TotalHeight: integer;
begin
TotalHeight := 0;
for I := 0 to ScrollBox1.ComponentCount - 1 do begin
if ScrollBox1.Components[i] is TPanel then
TotalHeight := TotalHeight + TPanel(ScrollBox1.Components[i]).Height;
if ScrollBox1.Components[i] is TSplitter then
TotalHeight := TotalHeight + TSplitter(ScrollBox1.Components[i]).Height;

end;

ScrollBox1.VertScrollBar.Range := TotalHeight;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
db: tDataBlock;
t: integer;
begin
t := 0;
BlockCount := 0;
for I := 0 to 3 do begin
db := tDataBlock.Create(ScrollBox1, t);
Inc(BlockCount);
end;

ConfigureScreen;

end;

{ tDataBlock }

constructor tDataBlock.Create(Owner: TWinControl; var t: integer);
begin
fOwner := Owner;

fPanel := TPanel.Create(Owner);
fPanel.Parent := Owner;
fPanel.Height := 150;
fPanel.Top := t;
fPanel.Align := alTop;
fPanel.AlignWithMargins := false;
fPanel.Color := clRed;
fPanel.ParentBackground := false;
fPanel.BorderWidth := 0;
fPanel.BorderStyle := bsNone;
fPanel.Ctl3D := false;
fPanel.AutoSize := false;
fPanel.UseDockManager := false;
t := fPanel.Top + Panel.Height + 1;

fLabel := TLabel.Create(self);
fLabel.Parent := fPanel;
fLabel.Align := altop;
fLabel.Caption := inttostr(fPanel.Height);
fLabel.Font.Size := 10;

fSplitter := TSplitter.Create(Owner);
fSplitter.Parent:= Owner;
fSplitter.Height := 3;
fsplitter.Top := t;
fSplitter.AutoSnap := false;
fSplitter.AlignWithMargins := false;
fSplitter.MinSize := 1;
fSplitter.Align := alTop;

t := fSplitter.Top + fSplitter.Height + 1;

end;

end.

Anyone that might help me here?

Thanks

Edited by: Thomas Amaddeo on Sep 13, 2015 1:57 AM

Peter Below

Posts: 1,227
Registered: 12/16/99
Re: resize controls beyond parent's client area
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 13, 2015 1:04 AM   in response to: Thomas Amaddeo in response to: Thomas Amaddeo
Thomas Amaddeo wrote:

I'm trying to replicate what is done by MS SQL Managment Studio like
asked in [this
page|http://stackoverflow.com/questions/13909756/how-to-resize-controls-beyond-parents-client-area]

Is there anyone that can help me solving this headache???

I have a ScrollBox, and in there, i create as many panels/splitters
as i need based on the number of query executed.

Here is just a try, but i can't make it work as i want. once panels
have reached the client area, i'm not able to resize them any bigger
that the main form client area.

You are aligning your panels alTop inside the scrollbox. That will not
work, it gets into conflict with the way a scrollbox scrolls its
content (by changing the control's Top or Left position). You also try
to set the scrollbox scrollbar's range manually. That also gets into
conflict with the automatic management of the scrollbar.

Starting with an empty scrollbox, just set the new panel's Left to 0,
Right to the scrollbox clientarea width, and Top to your current t
value, that should work better. The drawback is that you need to
manually handle any changes in the scrollbox width by resizing the
panels. Or try to set the right anchor, that may work as well (never
tried it myself).

--
Peter Below (TeamB)
Thomas Amaddeo

Posts: 3
Registered: 10/13/15
Re: resize controls beyond parent's client area
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 13, 2015 1:50 AM   in response to: Peter Below in response to: Peter Below
Hi Peter, thanks for the advice.
I've tried as you said but it didn't work though.

If i don't align panels alTop, the screen just becomes a mess and splitters are who knows where =).

Edited by: Thomas Amaddeo on Sep 13, 2015 2:45 AM
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: resize controls beyond parent's client area [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 13, 2015 4:31 AM   in response to: Thomas Amaddeo in response to: Thomas Amaddeo
Thomas Amaddeo wrote:

Hi Peter, thanks for the advice.
I've tried as you said but it didn't work though.

If i don't align panels alTop, the screen just becomes a mess and
splitters are who knows where =).

Splitters do not work unless they sit between aligned controls, usually
one that is aligned to a border and one that is alClient aligned. Using
splitters between your panels is not compatible with using a scrollbox,
I think.


--
Peter Below (TeamB)

Thomas Amaddeo

Posts: 3
Registered: 10/13/15
Re: resize controls beyond parent's client area [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 13, 2015 4:57 AM   in response to: Peter Below in response to: Peter Below
so what would you use to achieve that?

I thought that i could use the splitters OnCanResize event to increase panel and scrollbox heights...as i said it works as long they don't completely fill the client area....
John Treder

Posts: 349
Registered: 8/2/02
Re: resize controls beyond parent's client area [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 13, 2015 9:55 AM   in response to: Thomas Amaddeo in response to: Thomas Amaddeo
Thomas Amaddeo wrote:

so what would you use to achieve that?

I thought that i could use the splitters OnCanResize event to increase panel and scrollbox heights...as i said it works as long they don't completely fill the client area....

I don't know if it will work, but you could try putting a panel ("base panel") in the scrollbox, then putting your splitter-panels and splitters on the base panel. Then when you resize the base pane in perhaps an OnCanResize event handler, the scrollbox will do its thing.

--
nhoJ
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: resize controls beyond parent's client area [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 14, 2015 11:37 AM   in response to: John Treder in response to: John Treder
John Treder wrote:

Thomas Amaddeo wrote:

so what would you use to achieve that?

I thought that i could use the splitters OnCanResize event to
increase panel and scrollbox heights...as i said it works as long
they don't completely fill the client area....

I don't know if it will work, but you could try putting a panel
("base panel") in the scrollbox, then putting your splitter-panels
and splitters on the base panel. Then when you resize the base pane
in perhaps an OnCanResize event handler, the scrollbox will do its
thing.

Yes, that may work.

--
Peter Below (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02