Jump to content

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


jerome
 Share

Recommended Posts

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...