使用 FormattedText 对象,如何找出实际显示了多少文本?
如果我有这样的代码:
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));
...那么,如果它很长,则只有我(通过 sTheBook)传入的一些文本才会显示在屏幕上。我需要知道显示了多少,以便稍后显示其余部分!我可以轻松测量文本量,但通过一遍又一遍地渲染和重新渲染文本直到找到完全适合的文本来进行搜索似乎很愚蠢。
如果其他 WPF 文本渲染技术具有此功能,我愿意使用它。
谢谢!
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, 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过查看“宽度”和“高度”属性来简单地确定其大小。应用换行后,这将为您提供“所需的大小”。
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.