Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is the width of the text?
#3
(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
Reply


Messages In This Thread
What is the width of the text? - by I.Igor - 02-12-2021, 04:08 PM
RE: What is the width of the text? - by kudzu - 02-12-2021, 07:54 PM
RE: What is the width of the text? - by Alexandre Machado - 02-14-2021, 08:52 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)