I’m trying to find a way to make a certain text adapt to its control, in this case it’s a button (win.butt)
With the method below, given a string I want to find what is the maximum textsize possible to stay within 80% of the width of
the button controls that Im using.
I know that graphicsstringwidht uses pixels so I changed the units of the button fonts in pixels but still is not working.
Any clues pls, thanks
idealtextsize(word as string) as integer
Dim p as new picture (20,22,32)
p.Graphics.textfont=win.butt(1).textfont
p.Graphics.TextSize=win.butt(1).textsize
p.graphics.textunit=fontunits.Pixel
win.butt(1).TextUnit=fontunits.pixel
p.graphics.textsize=1
do
p.graphics.textsize=p.graphics.textsize+5
win.title=str(p.graphics.textsize)
loop until p.graphics.stringwidth(word)>=80*win.butt(1).width
return p.graphics.textsize
the method is slow and almost freezes and the captions “disappear”
what I do outside the method is this
button.textize=idealtextsize(word) ’ word is the caption for the button control