Recent

Author Topic: Extended AutoSize  (Read 7603 times)

korba812

  • Sr. Member
  • ****
  • Posts: 390
Extended AutoSize
« on: September 16, 2016, 01:39:49 pm »
I like AutoSize and Anchor Side, but they lack something (or maybe there is something about what I do not know).
For example, TEdit control does autosize only in height, but width is always the same (if I remember correctly is 60px). For TMemo, the height is set in such way that it shows only one line of text.
Assuming AutoSize is for automatically adjust size of controls based on font size or screen DPI, I suggest add property that indicate width for the control in characters, as it is calculated in the case of TDBGrid columns (width calculated based on the Field. DisplayWidth). Similarly, in case the of TMemo, the property indicating the number of rows to be displayed.
I know that the font glyphs have a different width, but if we accept the principle as in the case DBGrid columns, it will be enough (better than hardcoded 60px).

I enclose a sample project that shows what's going on.

lainz

  • Hero Member
  • *****
  • Posts: 4449
    • https://lainz.github.io/
Re: Extended AutoSize
« Reply #1 on: September 16, 2016, 04:34:22 pm »
You can create your own descendants of these classes and override this:

Code: Pascal  [Select][+][-]
  1. procedure CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer;
  2.       WithThemeSpace: boolean); override;

And then AutoSize will work as you coded it.

korba812

  • Sr. Member
  • ****
  • Posts: 390
Re: Extended AutoSize
« Reply #2 on: September 16, 2016, 04:57:06 pm »
I'm doing it exactly this way (see attached project to the first post). I have created a package with all controls that I use, and I use them successfully in my projects. So, in my humble opinion it would be useful solution in the LCL. But maybe there is a better solution which I do not know.

 

TinyPortal © 2005-2018