Discussion:
DrawTextEx question
(too old to reply)
Rick Roen
2003-07-18 15:12:05 UTC
Permalink
I'm trying to use DrawTextEx like this:

SetTextAlign( Printer.canvas.handle, TA_CENTER;
...
.some other printing code using TextOut
.

DrawTextEx( Printer.Canvas.handle, PChar( SomeText ), -1,
aRect, DT_SINGLELINE OR DT_CENTER OR DT_END_ELLIPSIS OR DT_TOP, nil );

Then the DrawTextEx does not print in the correct position, i.e. Centered.
It appears left aligned.

If I change to

SetTextAlign( Printer.canvas.handle, TA_LEFT );

before calling DrawTextEx then everything is printed as expected.

Any idea why? I would have expected that since the text align is set within
the call to DrawTextEx that any other alignment setting would be ignored.

TIA

Rick
Mike Lischke
2003-07-18 16:32:31 UTC
Permalink
Post by Rick Roen
Any idea why? I would have expected that since the text align is set within
the call to DrawTextEx that any other alignment setting would be ignored.
The text alignment setting does not cause text output functions to align the text in the given rectangle, but it tells Windows how to interpret the reference point you give with the output call. TA_LEFT means the point represents the left border of the string, while TA_CENTER means the given point represents the center of the string, so the text is centered around the given position.

Mike
--
www.delphi-gems.com
www.delphi-unicode.net
www.lischke-online.de
Rick Roen
2003-07-18 20:10:05 UTC
Permalink
Thanks for the explanation Mike.

Rick
Post by Rick Roen
Any idea why? I would have expected that since the text align is set within
the call to DrawTextEx that any other alignment setting would be ignored.
The text alignment setting does not cause text output functions to align the
text in the given rectangle, but it tells Windows how to interpret the
reference point you give with the output call. TA_LEFT means the point
represents the left border of the string, while TA_CENTER means the given
point represents the center of the string, so the text is centered around
the given position.

Mike
--
www.delphi-gems.com
www.delphi-unicode.net
www.lischke-online.de

Loading...