简体   繁体   中英

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.

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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