Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用FormattedText对象,如何确定实际显示了多少文本?_C#_Wpf_Windows_Text Formatting - Fatal编程技术网

C# 使用FormattedText对象,如何确定实际显示了多少文本?

C# 使用FormattedText对象,如何确定实际显示了多少文本?,c#,wpf,windows,text-formatting,C#,Wpf,Windows,Text Formatting,如果我有这样的代码: FormattedText text = new FormattedText(sTheBook, System.Globalization.CultureInfo.CurrentUICulture, System.Windows.FlowDirection.LeftToRight, new Typeface("Times New Roman"), 13, Brushes.Black); text.MaxTextWidth

如果我有这样的代码:

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具有此功能,我愿意使用其他WPF文本呈现技术


谢谢

您可以通过查看宽度和高度属性来确定其大小。这将在应用断线后为您提供“所需大小”