在WPF Richtextbox中更改fontsize后,应用程序变慢吗? [英] Application Slow After Change fontsize in a WPF richtextbox?

查看:79
本文介绍了在WPF Richtextbox中更改fontsize后,应用程序变慢吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WP richtextbox.我已经完成了将每行从当前插入符号位置导航到下一行,上一行等工作.它工作正常.我需要在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);

有效.但是执行此方法后,其他功能执行时间会很长.在NavigateNextLine()之前需要15ms至20ms.执行后需要40至50ms.i连续调用fontSize 4,5次,然后NavigateNextLine()花费100毫秒t0 120毫秒.

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?

致谢 阿琼

推荐答案

两者均应起作用:

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

OR

txtAppendValue.ApplyPropertyValue(TextElement.FontSizeProperty, 10.0)

这篇关于在WPF Richtextbox中更改fontsize后,应用程序变慢吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆