TextHeight Method

See Also9ROO0N7              Example2AQ6QTR>Low

Action

Returns the height of a text string as it would be printed in the current font of an object.

Syntax

[object.]TextHeight(stringexpression)

Remarks

The TextHeight method has these parts:

Part                           Description

 

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.


See Also

FontSize PropertyB3WV13

Scale MethodQ2ADWT

TextWidth Method8ZWV014


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.

End Sub