I feel like I should know how to do this but I’m having a mental block…
How do you calculate the length in pixels of a string shape? Is s is a string shape, s.text.len gives you the length in characters of the text. How can I convert that to pixels?
So that would work except Im going to draw the string shape onto a picture. But if the string is too large for the width of the picture I want to decrease the size of the font until it fits. But I dont think I can use g.stringwidth without drawing it first, can i?
set the font data for G to same as string shape
measure text size using G, adjust if you need to make it smaller
then take G font data and use it in string shape.
Why not just use DRAWSTRING instead of a string shape? Unless you are going to rotate it in which case the size kinda goes out the window
Yes you can. You could even outside a paint event using the graphics object of a temporary picture.
Or you could calculate string width, find out it will never fit and not draw the string at all.
FUNCTION getStringWidth(s as string, fontname as string,fontsize as single) as double // I think it returns INTEGER on WIndows
dim p as new picture(10,10)
dim g as graphics = p.graphics
g.textfont=fontname
g.textsize=fontsize
return g.stringwidth(s)
END FUNCTION