02-14-2021, 08:52 PM
(This post was last modified: 02-14-2021, 08:55 PM by Alexandre Machado.)
(02-12-2021, 04:08 PM)I.Igor Wrote: Hello.
I would sometimes like to dynamically set the size of the TIWListbox.
I was able to calculate the height of the ListBox1:
MyHeight := round(ListBox1.Items.Count * (ListBox1.Font.Size * ListBox1.Font.PixelsPerInch/72)) + ListBox1.Items.Count * 3;
I don't know how to calculate the width. In Delphi, canvas is used for this. But TIWListbox has no canvas.
How to calculate the width of any any row of a ListBox1?
You can't obtain it with 100% accuracy without code running on browser side, but you can get it close enough for most practical purposes.
Use existing TIWFont methods and properties, example:
You would get the height of a single item on the list with something like:
ListBox1.Font.PxSize (size in pixels of the font when rendered)
You can also use other methods like:
// convert any font size to pixel size
class function PtToPx(AFontSize: Integer): Integer;
// converts EM to pixels
class function EmToPx(AValue: Single; AFontSize: Integer): Integer;
e.g.:
x := TIWFont.EmToPx(1.1, 12);
x will get the size in pixels of a text which height is 1.1em, using font size 12.
with a little experimentation you can get it almost perfect