I've got this question:
I sometimes need the length and height of a text in "Graphics mode" when using "GraphicsWindow" with "DrawText()" or "DrawBoundText()". How can I calculate the length and height of a text depending on the font name and font size?
Regards ... Gregor
But I don't think that the text shape can do that, can it?
But there is a solution in Small Visual basic by using the Controls.AddLabel
method to draw the text in a label to have full control of it. We can change the font properties of the label, then call the FitContentSize
to force the label to resize its width and height to fit its text, so we can use its Width and Height properties to get the text size.
Note that sVB allows to draw all controls (except menus) on the Graphics Window. Try this:
Lbl = Controls.AddLabel("Hello sVB", 100, 100)
Lbl.FontSize = 20
Lbl.FitContentSize()
GraphicsWindow.ShowMessage(
Text.Format(
"Width = [1], Height = [2]",
{Lbl.Width, Lbl.Height}
),
"Text size"
)