c# - 可以在 RichtextBox 中加快线条的着色速度吗?

标签 c# winforms performance richtextbox

问题

是否可以加快 RichtextBox 中线条的着色速度?

情况

我有日志文件,其中有错误的行必须用彩色显示。为此,我使用了性能很差的 RichttextBox 控件。

到目前为止我达到了什么

我已经这样做来加快速度:

之后,我需要 11 秒来为 2000 行中的 100 行着色,而不是之前的 40 秒。

其他问题

还有其他几个问题,如提到的 Richedit50W关于加速 RichtextBox 或着色。但没有答案有助于加快着色。

我的代码

我还能做些什么来加快速度吗?

private void ColorizeLog(List<int> ErrorLines)
{
    // The List "ErrorLines" is filled with the wanted line numbers
    // and was build before filling the RichtextBow with the log data


    // Counting the lines before the for..next is 50% faster than:
    //      for (int lineNo = 0; lineNo < this.richTextbox50_Log.Lines.Count(); lineNo++)   
    //      in combination the other usage of "countLines" deeper in the code
    int countLines = this.richTextbox50_Log.Lines.Count();
    for (int lineNo = 0; lineNo < countLines; lineNo++)
    {

        if (ErrorLines.IndexOf(lineNo) >= 0)
        {
            int pos1 = this.richTextbox50_Log.GetFirstCharIndexFromLine(lineNo);
            int pos2 = lineNo < countLines  - 1 ?
                        this.richTextbox50_Log.GetFirstCharIndexFromLine(lineNo + 1) - 1 :
                        this.richTextbox50_Log.Text.Length;

            this.richTextbox50_Log.Select(pos1, pos2 - pos1);
            this.richTextbox50_Log.SelectionColor = Color.White;
            this.richTextbox50_Log.SelectionBackColor = Color.Red;
        }
}

最佳答案

For one of my projects, I have felt the need of a text editor with syntax highlighting. At first, I used a component inherited from RichTextBox, but while using it for a large amount of text I found out that RichTextBox highlights very slowly a large number of colored fragments (from 200 and more). When such highlighting has to be made in a dynamic way, it causes a serious problem.

http://www.codeproject.com/Articles/161871/Fast-Colored-TextBox-for-syntax-highlighting

我认为 RichTextBox 有时只是一个 b***...

关于c# - 可以在 RichtextBox 中加快线条的着色速度吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37678212/

相关文章:

c# - 如何在我的 C# 类中运行 jQuery?

c# - DataGridView 中的计算列绑定(bind)到一个对象

database - 为什么 Oracle 使用 DBMS_STATS.GATHER_TABLE_STATS?

performance - 生产应用程序的监控和警报

c# - 使用命名空间将 Json 转换为 XML 字符串?

c# - 在 Cake 脚本中找不到 Linq 扩展方法

C# WPF 使用 ItemsControl 管理嵌套结构

c# - 如何防止使用 alt + F4 关闭任何表单

c# - 加快将字符串列表加载到 Treeview 的速度

php - 具有大数据性能的MySQL查询