See Also Example
Returns the height of a text string as it would be printed in the current font of an object.
The TextHeight method has these parts:
object Object (non MDI form, picture box, or Printer object) that determines the font size upon which the text height is based.
stringexpression Text string for which the text height is determined.
The height is expressed in terms of the Scale coordinate system in effect for object. Use TextHeight to determine the amount of vertical space required to display the text. The height returned includes the normal "leading" space above and below the string, so you can use the height to calculate and position multiple lines of text within a form, picture box, or Printer object. If stringexpression contains embedded carriage returns, TextHeight returns the cumulative height of the lines, including the leading space above and below each line.
TextHeight Method Example
The TextHeight method is used to center a line vertically on a form. To try this example, paste the code into the Declarations section of a form. Then press F5 and click the form.
Sub Form_Click ()
Dim HalfWidth, HalfHeight, Msg ' Declare variable.
AutoRedraw = -1 ' Turn on AutoRedraw.
BackColor = QBColor(4) ' Set background color.
ForeColor = QBColor(15) ' Set foreground color.
Msg = "Visual Basic" ' Create message.
Fontsize = 48 ' Set font size.
HalfWidth = TextWidth(Msg) / 2 ' Calculate half width.
HalfHeight = TextHeight(Msg) / 2 ' Calculate half height.
CurrentX = ScaleWidth / 2 - HalfWidth ' Set X.
CurrentY = ScaleHeight / 2 - HalfHeight ' Set Y.
Print Msg ' Print message.