_PRINTWIDTH - mkilgore/QB64pe GitHub Wiki

The _PRINTWIDTH function returns the width in pixels of the text string specified.

Syntax

pixelWidth% = _PRINTWIDTH(textToPrint$[,])

Description

  • textToPrint$ is any literal or variable STRING value.
  • If the destinationHandle& is omitted, the current destination image or screen page is used.
  • Useful to find the width of the font print string before actually printing it.
  • Can be used with variable-width fonts or built-in fonts, unlike _FONTWIDTH which requires a MONOSPACE font handle.
  • In SCREEN 0, _PRINTWIDTH returns the character length of a text string, exactly as LEN(textToPrint$) (version 1.000 and up).

Examples

Example: SUB returns font or screen mode's text block size using _PRINTWIDTH and _FONTHEIGHT without a handle parameter.

TextSize wide&, high&       'get the font or current screen mode's text block pixel size

_PRINTSTRING (20, 100), CHR$(1) + STR$(wide&) + " X" + STR$(high&) + " " + CHR$(2)

END

SUB TextSize (TextWidth&, TextHeight&)
TextWidth& = _PRINTWIDTH("W")     'measure width of one font or text character
TextHeight& = _FONTHEIGHT         'can measure normal text block heights also   
END SUB '' ''
Code by Ted Weissgerber Note: The SUB procedure does not need the font handle for font sizes after _FONT enables one.

See also


Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page
⚠️ **GitHub.com Fallback** ⚠️