开发者

Using a FormattedText object, how do I find out how much of my text was actually displayed?

If I have code like this:

FormattedText text = new FormattedText(sTheBook,
      System.Globalization.CultureInfo.CurrentUICulture,
      System.Windows.FlowDirection.LeftToRight, 
      new Typeface("Times New Roman"), 
      13, Brushes.Black);

text.MaxTextWidth = 300;
text.MaxTextHeight = 600;
text.TextAlignment = TextAlignment.Justify;
dc.DrawText(text, new Point(10, 0));

...then, if it is long, only some of the text that I passed in (via sTheBook) will be displayed on the screen. I need to know how much was displayed so I can display the rest later! I can easily measure an amount of text开发者_StackOverflow中文版, but it seems silly to do a search by rendering and re-rendering my text over and over until I find the piece that fits exactly.

I'd be open to using some other WPF text rendering technique if it has this functionality.

Thanks!


You could simply determine its size by looking at the Width and Height properties. That will give you the "desired size" after line breaking has been applied.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜