StringHeight ( string$ )
Parameters
| string$ - the text to measure |
Description
|
Returns how tall a line of text is in pixels in the current font. It is the partner of StringWidth for laying text out - stepping down a list, sizing a dialogue box around its contents, or working out where the next line of a wrapped paragraph goes. Be aware that the string you pass makes no difference to the answer. The height comes from the font, not from the characters, so a string of capitals, a string of lower-case letters and an empty string all measure the same, and it returns exactly what FontHeight does. It also does not grow for a multi-line string: if you want the height of several lines, count the lines yourself and multiply. Like the other measuring commands it reports on whichever font SetFont selected last, so measure after switching. See also: StringWidth, FontHeight, FontWidth, Text, SetFont. |
Example
; StringHeight Example ; -------------------- Graphics 640,480,0,2 SetBuffer BackBuffer() ; A small font for the info overlay info_font=LoadFont("Arial",14) size=32 font=LoadFont("Arial",size) msg$="LEVEL COMPLETE" While Not KeyDown(1) ; [ / ] shrink or grow the font (reloaded at the new size) If KeyHit(27) And size<64 Then FreeFont font size=size+8 font=LoadFont("Arial",size) End If If KeyHit(26) And size>16 Then FreeFont font size=size-8 font=LoadFont("Arial",size) End If Cls SetFont font ; StringHeight returns the string's pixel height in the current font - ; the classic use is centring text vertically h=StringHeight(msg$) w=StringWidth(msg$) y=(480-h)/2 Color 255,255,255 Text (640-w)/2,y,msg$ ; Guide lines exactly at the top and bottom of the string Color 80,200,255 Line 40,y,600,y Line 40,y+h,600,y+h SetFont info_font Color 255,255,255 Text 0,0,"[ / ] change font size Esc: exit" Text 0,20,"Arial "+size+"pt: StringHeight(msg$) = "+h+", so y = (480-"+h+")/2 = "+y Flip Wend End
Index