Jump to content
Sign in to follow this  
jerome

Function to print in a label any string len using "..."

Recommended Posts

jerome

Hi,

Here are a source code to fit any string text into a fixed size label. String too long are shortened automatically by using "..." in the middle of the string.

Func AdaptStringToSize($string, $font, $size, $width)
    $len = StringLen($string)
    $gui = GuiCreate("", $width+1, 1,-1, -1)
    GUISetFont($size, 400, 0, $font)
    $str = $string
    Do
        $label = GuiCtrlCreateLabel($str, 0, 0)
        $pos = ControlGetPos($gui, $str, $label)
        If $pos[2] > $width Then 
            $sub = Int(($width-$pos[2])/$size)-1
            If $sub <=0 then $sub = 1
            $len -= $sub
            $str = LimitStringSize($string, $len)
        EndIf
    Until $pos[2] <= $width
    GUIDelete($gui)
    GUISetFont($size, 400, 0, $font)
    Return $str
EndFunc

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  

×