Forum > LCL

Extended AutoSize


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.

You can create your own descendants of these classes and override this:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer;      WithThemeSpace: boolean); override;
And then AutoSize will work as you coded it.

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.


[0] Message Index

Go to full version