DrawText Method (AForm)

Draws text on an object.

Syntax

Object.DrawText ( sText [,enDrawText] [,fLeft] [,fTop] [,fWidth] [,fHeight] )

The DrawText method syntax has the following parts:

 

Name

Type

Description

Object

AForm

AForm object

sText

BSTR

The text to be drawn.

enDrawText

Val enumAFormDrawText

An integer specifying the method of formatting the text. It can be any combination of the values of enumAFormDrawText (combined using the bitwise OR operator).

fLeft

Val Variant

The left-most position to start drawing the text relative to the top left position on the object.

fTop

Val Variant

The top-most position to start drawing the text relative to the top left position on the object.

fWidth

Var Variant

The width of the text area.

fHeight

Var Variant

The height of the text area.

Where

enumAFormDrawText can be one of the following:

 

Name

Value

Description

aformDrawTextTop

0

Top. Specifies top-justified text (single line only).

aformDrawTextLeft

0

Left. Aligns the text flush-left.

aformDrawTextCenter

1

Center. Centers the text horizontally.

aformDrawTextRight

2

Right. Aligns the text flush-right.

aformDrawTextVCenter

4

Vertical Center. Specifies vertically centered text (single line only).

aformDrawTextBottom

8

Bottom. Specifies bottom-justified text. This value must be combined with aformDrawTextSingleLine.

aformDrawTextWordBreak

16

Word break. Specifies word-breaking. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by fWidth and fHeight. A carriage return–linefeed sequence will also break the line.

aformDrawTextSingleLine

32

Single line. Specifies single line only. Carriage returns and linefeeds do not break the line.

aformDrawTextExpandTabs

64

Expand tabs. Expands tab characters. The default number of characters per tab is eight.

aformDrawTextTabStop

128

Tab stop. Sets tab stops. The high-order byte of enumAFormDrawText is the number of characters for each tab. The default number of characters per tab is eight.

aformDrawTextNoClip

256

No clip. Draws without clipping. DrawText is somewhat faster when aformDrawTextNoClip is used.

aformDrawTextExternalLeading

512

External leading. Includes the font’s external leading in the line height. Normally, external leading is not included in the height of a line of text.

aformDrawTextCalcRect

1024

Calculate the rectangle. Determines the width and height of the rectangle. If there are multiple lines of text, DrawText will use the width of the rectangle indicated by fWidth and extend the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText will modify the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text, but does not draw the text.

aformDrawTextNoPrefix

2048

No prefix. Turns off processing of prefix characters. Normally, DrawText interprets the ampersand (&) mnemonic-prefix character as a directive to underscore the character that follows, and the two-ampersand (&&) mnemonic-prefix characters as a directive to print a single ampersand. By specifying aformDrawTextNoPrefix, this processing is turned off.

Comments

DrawText formats text in the given rectangle by expanding tabs into appropriate spaces, aligning text to the left, right, or center of the given rectangle, and breaking text into lines that fit within the given rectangle. The type of formatting is specified by enumAFormDrawText. The enumAFormDrawText can be created by a bitwise OR operation, for example, (aformDrawTextLeft OR aformDrawTextVCenter) to combine two types of formatting.

DrawText uses the device context’s selected font, text color, and background color to draw the text. These can be set using the form's Font, ForeColor, BackColor and the FontTransparent properties. Unless the aformDrawTextNoClip format is used, DrawText clips the text so that the text does not appear outside the given rectangle. All formatting is assumed to have multiple lines unless the aformDrawTextSingleLine format is given.

If the selected font is too large for the specified rectangle, DrawText does not attempt to substitute a smaller font.

If the aformDrawTextCalcRect flag is specified, the rectangle specified by fWidth and fHeight will be updated to reflect the width and height needed to draw the text.

The values aformDrawTextdCalcRect, aformDrawTextExternalLeading, aformDrawTextNoclip, and aformDrawTextNoPrefix cannot be used with the aformDrawTextTabStop value.

If fWidth and fTop are not specified, DrawText will use the current position for drawing the text.

The method is not applicable for MDI Form type since drawing functions are not supported for MDI Forms.

Example

The following statement draws the text string "Hello World" on the AForm starting relative to the top left corner of the object, at left = 50 units and top = 60 units, in a rectangle of width = 70 units and height = 80:

DrawText("Hello World", (aformDrawTextLeft OR aformDrawTextVCenter),50,60,100,80)

Applies to

AForm

See Also

BackColor, DrawMode, DrawStyle, DrawWidth, FillColor, Font, Font3D, FontTransparent, ForeColor