简体   繁体   English

在WPF Richtextbox中更改fontsize后,应用程序变慢吗?

[英]Application Slow After Change fontsize in a WPF richtextbox?

i am working with WP richtextbox.i done to navigate each line from current caret position to nextline,previousline etc.it works fine.i need to dynamically change fontsize in richtextbox. 我正在使用WP richtextbox.i完成了将每行从当前插入符号位置导航到下一行,上一行等。它工作正常。我需要在Richtextbox中动态更改字体大小。

i used this below methods to change font size: 我使用以下方法来更改字体大小:

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

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

it works.But after execute this methods,the other functionality execution time taken is high.Before that NavigateNextLine() taken 15ms to 20ms.After execution it takes 40 to 50 ms.i continuously call the fontSize 4,5 times then the NavigateNextLine() takes 100ms t0 120 ms. 但是执行此方法后,其他功能的执行时间很长。在此之前, 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;
            }
        }

SO whats the problem?how to resolve it? 那么问题是什么?如何解决?

regards Arjun 问候阿琼

Both should work: 两者都应该工作:

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

OR 要么

txtAppendValue.ApplyPropertyValue(TextElement.FontSizeProperty, 10.0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM