Quantcast
Viewing all articles
Browse latest Browse all 3780

Drawtext right align in canvas

I’m trying to draw right-aligned text in a canvas.
While drawing left-aligned text with its proper wrapwidth works OK in that when the text reaches wrapwidth itvstarts a new line, when I try drawing right align text and the text reaches wrapwidth, it correctly starts a new line but it also continues to move behind, that is, outside, the left margin and the new line does not start on the right, but on the left.

g.DrawingColor = pQRTxtColor
g.FontName = pFontName
g.FontUnit = FontUnits.Point
g.FontSize = pFontSize
g.Bold = isBold
g.Italic = isItalic

dim mTop2 as Integer = g.TextHeight
dim r as String = someText
g.DrawText(r, g.Width - g.TextWidth(r) - leftMargin, mTop2, leftMargin-g.width)

For instance, the text: “I go to see my mother somewhere”: according to the given wrapwidth, let us suppose it wraps after “mother”.
I expect to see:
“I go to see my mother
… … … …somewhere” // i.e. at the right margin
But what I see is:
“see my mother
where” //i.e. at the left margin

That is “I go to” (of the first line) and “some” (of the second line) have moved outside the left margin and “where” (of the second line) does not draw from the right margin but from the left margin. And the more I type, the more the text moves outside the left margin till I don’t see anything anymore.

Utterly confused. Can anybody tell me how to properly adjust the “X” and “wrapwidth” values of drawtext?
Thank you.

6 posts - 4 participants

Read full topic


Viewing all articles
Browse latest Browse all 3780

Trending Articles