how to display a TextRange in a form?

R

Ramon.wzhong

hi all,
i have to display a TextRange of a TextFrame in a form, so i get some
parameters from the TextRange, such as BoundWidth, BoundHeight and
Font.Size. but when i use these parameters to draw it in a form, the content
of the textRange is beyong the rectangle which width = BoundWidth and height
= BoundHeight. what is the problem? I had considered the influence of DPI and
tried to convert size to pixel, but it is useless. the following is the codes:

1. get the bound rectange of the TextRange:
TextRange text;
...
float left = text.BoundLeft ;
float width = text.BoundWidth ;
float top = text.BoundTop ;
float height = text.BoundHeight ;
RectangleF rect = new RectangleF(left, top, width, height);

Font font = new Font(text.Font.Name, text.Font.Size);
2.Display:
SizeF pos = g.MeasureString(text.Text, font);
Console.WriteLine("Pos: " + pos + ", Rect: " + rect);
g.DrawString(text.Text, font, brush, rect);

in step 2, pos.Width is not equal rect.Width and pos.Height is not equal
rect.Height, why?

thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top