04-21-2024, 06:34 AM
Code: (Select All)
Sub SafeLoadFont (font#)
'Safely loads a font without destroying our current print location and making it revert to the top left corner.
down = CsrLin: right = Pos(0)
down = (down - 1) * _FontHeight
If _FontWidth <> 0 Then 'weed start with a monospace font
right = (right - 1) * _PrintWidth(" ") 'convert the monospace LOC to a graphic X coordinate
End If
_Font font#
If _FontWidth <> 0 Then 'we swapped to a monospace font
right = (right / _PrintWidth(" ")) + 1 'convert the graphic X coordinate back to a monospace LOC column
End If
down = (down / _FontHeight) + 1
If right < 1 Then right = 1
Locate down, right
End Sub
Instead of using _FONT to swap to the new font, use _SafeLoadFont instead. It's been a standard part of my extended toolbox of routines which I make use of for years now.
![Smile Smile](https://qb64phoenix.com/forum/images/smilies/smile.png)