Mega Code Archive

 
Categories / Delphi / Examples
 

Resizeall

Subject: Re: Resizing Components Hello Richard, I tried your sample with small changes and it works fine. Can you sujest how to change also font size of components during resizing. Thanks Israel Nemlich Richard Ebbs wrote: > From: Richard Ebbs <richebbs@nildram.co.uk> > To: Israel Nemlich <inasakim@inter.net.il> > Subject: Form Resize > > Hi Israel > > re your query > > > I need help on how to resize (automatically) > > and all it's components every time the form > > is resized. > > -off the top of my head I think you'd need > something like this: > 1) a couple of global variable to keep track > of the 'old' form width and height, eg > > var > oldFormWidth, oldFormHeight: Integer; > > and some code in the OnResize event handler > for the form like this perhaps: > > procedure MyForm.FormResize(Sender: TObject) > var > widthRatio, heightRatio: Double; > compIndex: Integer; > begin > widthRatio := (MyForm.Width / oldFormWidth); > heightRatio := (MyForm.Height / oldFormHeight); > for compIndex := 0 to (ComponentCount - 1) do > begin > Components[compIndex].Width := Round(Components[compIndex].Width * > widthRatio); Components[compIndex].Height := > Round(Components[compIndex].Height * heightRatio); > end; > oldFormWidth := MyForm.Width; > oldFormHeight := MyForm.Height; > end; > > so that every time the form is resized all > sub-components are resized by the same ratio > in both the X and Y directions... > I haven't tested the code but it shouldn't be > far off... > (although resizing [eg button] text to an an > appropriate size might be a little fiddly..?) > > Hope this is useful. > > Richard Ebbs