04-09-2023, 12:25 AM
And centering in anywhere, any size boxes:
Code: (Select All)
_Title "Centering text inside anywhere box" ' b+ 2023-04-08
Screen _NewImage(800, 600, 32)
f& = _LoadFont("c:\WINDOWS\Fonts\arial.ttf", 24, "bold")
_Font f&
_PrintMode _KeepBackground
MessageBox 10, 10, 450, 40, "Centering text inside a box of X's, ...zzz", &HFF0000FF, &HFFFFFFFF
Sleep
f& = _LoadFont("c:\WINDOWS\Fonts\inkfree.ttf", 40)
_Font f&
MessageBox _Width - 410, _Height - 75, 400, 65, "bplus was here, ...zzz", &HFFFF0000, &HFFBBBBFF
Sleep
' assuming font is loaded and _font handle activated AND _PrintMode _KeepBackground
' assuming message will fit inside the giver box w and h (width and height)
Sub MessageBox (leftX, topY, w, h, message$, boxColor~&, PrintColor~&)
pwMessage = _PrintWidth(message$) ' print width of message$
fh = _FontHeight
Line (leftX, topY)-Step(w, h), boxColor~&, BF
Color PrintColor~&
Line (leftX + 2, topY + 2)-Step(w - 4, h - 4), , B
Line (leftX + 4, topY + 4)-Step(w - 8, h - 8), , B
' for some reason fonts like to press closer to top than bottom, so /1.75 instead of /2
_PrintString (leftX + (w - pwMessage) / 2, topY + (h - fh) / 1.75), message$ ' for perfect center
End Sub
b = b + ...