Jump to content
Sign in to follow this  
AustrianOak

measuring how long input text is?

Recommended Posts

AustrianOak

is there a function for this? i want to measure how long it is so i can make the right size label for it...

Share this post


Link to post
Share on other sites
smashly

measure string

Or

AutoIt Help file under User Defined Functions -> WinAPI Management -> _WinAPI_GetTextExtentPoint32()

Edited by smashly

Share this post


Link to post
Share on other sites
AustrianOak

the label gets cut off if i make it to long

heres what im doing:

$datalabel = GUICtrlRead($input)
$leng = _MeasureString($datalabel, $Arial, 12)
$newlabel = GUICtrlCreateLabel($datalabel, 24, 470, $leng, 20)
GUISetState(-1, $GUI_ONTOP)
GUICtrlSetState($newlabel, $GUI_SHOW)

now im not sure if the font is arial 12 because i didnt specify it. its just the font that comes when you type into any regular input. my input i think is 100 by 20 if that'll make any difference...

Share this post


Link to post
Share on other sites
smashly

default font size for Autoit gui/controls will be 8.5

Also if your using the measure string function I wrote then the way you have it it's returning an array,

$leng = _MeasureString($datalabel, "Arial", 8.5)

$leng[0] = Width of the string

$leng[1] = Height of the string

you can return just the width or height

$leng = _MeasureString($datalabel, "Arial", 8.5, -1, -1, -1, 0)

$leng = Width of the string

$leng = _MeasureString($datalabel, "Arial", 8.5, -1, -1, -1, 1)

$leng = Height of the string

Edited by smashly

Share this post


Link to post
Share on other sites
AustrianOak

ok, i changed my code to 8.5 like this:

$datalabel = GUICtrlRead($input)
$leng = _MeasureString($datalabel, $Arial, 8.5)
$newlabel = GUICtrlCreateLabel($datalabel, 24, 470, $leng, 20)
GUISetState(-1, $GUI_ONTOP)
GUICtrlSetState($newlabel, $GUI_SHOW)

but it still didnt change anything. the label text is still getting cut off...

Share this post


Link to post
Share on other sites
smashly

Look up and read my edited post..

The way your using the measurestring function it's returning an array

$leng = _MeasureString($datalabel, $Arial, 8.5)

$newlabel = GUICtrlCreateLabel($datalabel, 24, 470, $leng[0], 20)

Edited by smashly

Share this post


Link to post
Share on other sites
AustrianOak

awesome. great function man thanks a bunch.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.