Recent

Author Topic: TImage and TListBox relative to window size  (Read 740 times)

bjlockie1

  • New member
  • *
  • Posts: 8
TImage and TListBox relative to window size
« on: November 11, 2020, 08:19:11 pm »
I created an application with a TImage and TListBox.
I want the width and height of the TImage and TListBox to resize relative to the window when I resize the window.
They are both on the TMainForm.
I've played with the properties but both stay the fixed size they opened as.
The code is online at https://github.com/bjlockie/pix

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: TImage and TListBox relative to window size
« Reply #1 on: November 11, 2020, 09:40:50 pm »
If I were you, I would:

1) First, set the listbox aligned to alLeft and embed the TImage, TEdits, etc. into a TPanel aligned as alClient. Then calculate and set the width of the list box in the OnResize event of the form and you're done.

Note that you can also keep the design and basically re-calculate the new widths of each control at OnResize, but it's easier with a judicious use of panels (or a similar container).

2) Use Anchors and BorderSpacing to position each control relative to the others; doing it that way the design will keep more or less the same when changing sizes and it will be more adaptable if the conditions change, for example in HighDPI systems and such.

That's all I can say after a quick glance.
« Last Edit: November 11, 2020, 09:42:51 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018