【问题标题】:Application Slow After Change fontsize in a WPF richtextbox?在 WPF 富文本框中更改字体大小后应用程序变慢?
【发布时间】:2016-04-24 12:58:33
【问题描述】:

我正在使用 WP richtextbox。我已经完成了将每一行从当前插入符号位置导航到下一行、上一行等。它工作正常。我需要动态更改richtextbox 中的字体大小。

我使用以下方法来更改字体大小:

 myrichtextbox.SetValue(TextElement.FontSizeProperty, fontSizedouble +10);

  myrichtextbox.FontSize = (txtAppendValue.FontSize + 10);

它可以工作。但是执行此方法后,其他功能执行时间很长。在此之前NavigateNextLine() 需要 15 毫秒到 20 毫秒。执行后需要 40 到 50 毫秒。然后我连续调用 fontSize 4,5 次NavigateNextLine() 需要 100 毫秒 t0 120 毫秒。

public void NavigateNextLine()
{
  Int32 lineNumber;
                txtAppendValue.CaretPosition.GetLineStartPosition(-int.MaxValue, out lineNumber);
                Int32 iLineIndex = System.Math.Abs(lineNumber);
                Int32 iCurrentStart = 0;
                Int32 iCurWordLength = 0;


                for (Int32 icnt = 0; icnt <= iLineIndex; icnt++)
                {
                    m_strCurLineText = GetLineText(txtAppendValue.CaretPosition.GetLineStartPosition(lineNumber), 0, null);
                    iCurrentStart = iCurrentStart + m_strCurLineText.Length;
                    lineNumber += 1;
                }
  String[] strArr = m_strCurLineText.Split(' ');
                if (strArr.Length > 0)
                {
                    iCurWordLength = strArr[0].Length; // Get the first word length of current line
                    if (iCurWordLength == 0)
                    {
                        iCurWordLength = strArr[1].Length;
                        iCurrentStart = iCurrentStart + 1;
                    }
                }
                else
                {
                    iCurWordLength = m_strCurLineText.Length; //to get single word line length
                }

                NewStart = iCurrentStart;
}





 String GetLineText(TextPointer TextPointer, int LineRltv = 0, string Default = null)
        {
            TextPointer tp1 = TextPointer.GetLineStartPosition(LineRltv);
            if (tp1 == null)
            {
                return Default;
            }
            else
            {
                tpNextLine2 = tp1.GetLineStartPosition(1);

                TextRange tr = null;
                if (tpNextLine2 == null)
                {
                    tpNextLine2 = txtAppendValue.Document.ContentEnd;
                }
                tr = new TextRange(tp1, tpNextLine2);
                return tr.Text;
            }
        }

那么问题是什么?如何解决?

问候 阿琼

【问题讨论】:

  • 发布您的代码以获取其余功能
  • @Muds :现在检查一下。

标签: c# wpf performance fonts richtextbox


【解决方案1】:

两者都应该工作:

txtAppendValue.ApplyPropertyValue(TextElement.FontSizeProperty, (double)10);

txtAppendValue.ApplyPropertyValue(TextElement.FontSizeProperty, 10.0)

【讨论】:

  • @Vivek : 两者都应该工作。我的问题是在执行了这个另一个功能后执行速度很慢。我也试过这个。
  • @arjun ok 找到了解决方案
猜你喜欢
  • 2012-12-21
  • 2011-12-08
  • 1970-01-01
  • 2012-05-11
  • 1970-01-01
  • 2012-05-16
  • 1970-01-01
  • 2018-09-26
  • 1970-01-01
相关资源
最近更新 更多