Sign in to follow this  
Followers 0
AustrianOak

measuring how long input text is?

7 posts in this topic

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



#2 ·  Posted (edited)

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

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

#4 ·  Posted (edited)

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

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

#6 ·  Posted (edited)

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

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  
Followers 0