jerome Posted June 13, 2007 Share Posted June 13, 2007 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now