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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatic resizing of panels in a form? 1

Status
Not open for further replies.

pierrotsc

Programmer
Nov 25, 2007
358
0
0
US
I have a form with 2 panels. Right now i have the left one that has align set to alcustome with akleft,aktop and akbottom set to true. The right panel has akright,aktop and akbottom set to true.
The issue is that if I maximize the form then there's a huge gap between the two panels. I would like both of them to stay stuck together and do not leave a gap between. The panels have the same size so when maximized they still should be the same size.
Can it be done?
Thanks.
PO
 
not standard, I think.

one way to it is like this:

take a form put 3 panels on to it

- panel1 and panel2 must be inside of panel3
- panel3 alignment is set to alClient
- use the onresize event of panel3 to resize the containing panels

like this:

Code:
unit Unit12;

interface

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

type
  TForm12 = class(TForm)
    Panel3: TPanel;
    Panel1: TPanel;
    Panel2: TPanel;
    procedure Panel3Resize(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form12: TForm12;

implementation

{$R *.dfm}

procedure TForm12.FormCreate(Sender: TObject);
begin
 Panel1.Left := 0;
 Panel1.Top := 0;
 Panel2.Top := 0;
end;

procedure TForm12.Panel3Resize(Sender: TObject);
begin
 Panel1.Width := Panel3.Width div 2;
 Panel2.Width := Panel3.Width div 2;
 Panel2.Left := Panel1.Width;
 Panel1.Height := Panel3.Height;
 Panel2.Height := Panel3.Height;
end;

end.

Cheers,
Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Just a thought but would it work by setting the alignment too?

Panel1.align := alleft;
Panel2.align := alclient;

procedure TForm12.Panel3Resize(Sender: TObject);
begin
Panel1.Width := Panel3.Width div 2;
application.processmessages;
end;

www.radbmx.co.uk
 
a simpler way.

2 panels

panel1 align left
panel2 align client

procedure TForm1.FormResize(Sender: TObject);
begin
panel1.Width := clientwidth div 2;
end;



Aaron
 
I'd stick a application.processmessages;
in the resize too though :)

www.radbmx.co.uk
 
I'd stick a application.processmessages;
in the resize too though :)
There's no need to do that. He's modifying child control sizes, not the size of the form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top