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

Good way to resize form components on form resize?

Status
Not open for further replies.

CADTenchy

Technical User
Dec 12, 2007
237
GB
Hi,

I have a simple form with a few basic components on it.
I've put some size restraints on resizing the form, to stop it being resized to a stupid size, small or large.

To keep the components looking how I want them relative to the form size, I've used the code below.

Is this a good way to do it? I'm concerned about appearances depending on PC setup, only got my laptop to test on right now.

Code:
procedure TSDIAppForm.FormResize(Sender: TObject);
begin
ColumnListBox1.Width := ClientWidth-10;
ColumnListBox1.Height := ClientHeight-90;
Edit2.Width := ClientWidth-100;
Button3.Left := ClientWidth-240;
Button3.Top := ClientHeight-48;
Button2.Top := Button3.Top; 
end;
 
Use the Align property of components. The Client setting will force a component to fill it's available surrounding area. Separate blocks of components using Panel components. I don't have Delphi on this computer, so I can't remember what it's called, but it's on the Additional tab and is a divider of sorts.

If a component doesn't have an Align property (eg. TLabel), put them on a Panel, or use TStaticLabel.

The Align property also has a Custom setting, that generates an event where you can manually plug in figures, but I don't have any experience using it.
 
Futher to what Griffyn has said, you can also use the Anchors property to ensure the left/top/right/bottom of your control always stays in the same position relative to its parent.
This should give you the behaviour you're looking for without the need for any code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top