Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread Pixels and font size calculation
Fri, May 19 2017 8:27 AMPermanent Link

thomh

Is it possible to calculate this?

I have a TEdit with Width = 400 and Font size = 12

I have AString whose length is 250 chars

How would I calculate how many chars of AString I can visibly fit into the TEdit control based on its Width property?

So TEdit.Text := Copy(AString, 1, XXX);

Thanks.

// Thom
Fri, May 19 2017 9:04 AMPermanent Link

Matthew Jones

thomh wrote:

> How would I calculate how many chars of AString I can visibly fit into the TEdit control based on its Width property?

It all starts with this:

nWidth := InterfaceManager.ContentWidth(editText.Font, AString);

--

Matthew Jones
Fri, May 19 2017 10:20 AMPermanent Link

thomh

"Matthew Jones" wrote:

>It all starts with this:
>
>nWidth := InterfaceManager.ContentWidth(editText.Font, AString);

Thanks, Matthew.

Using that on the string gave me a nWidth = 593.

The Edit control has a Width = 400.

So how many chars of the string do I need to copy to fill up the TEdit control whose width is 400 ?

// Thom
Fri, May 19 2017 11:48 AMPermanent Link

Matthew Jones

thomh wrote:

> So how many chars of the string do I need to copy to fill up the TEdit control whose width is 400 ?

Create a temporary copy of the string. Loop around measuring the string and deleting a character from the end until it fits.

--

Matthew Jones
Fri, May 19 2017 12:57 PMPermanent Link

thomh

"Matthew Jones" wrote:

>Create a temporary copy of the string. Loop around measuring the string and deleting a character from the end until it >fits.

Got it. Thanks, Matthew.

// Thom
Fri, May 19 2017 2:28 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Thom,

Just be forewarned: measuring strings in the browser is *slowwww*.  It's why EWB goes to very great lengths to do so as sparingly as possible.

Tim Young
Elevate Software
www.elevatesoft.com
Image