我有大量的文本文件,我逐行处理并将结果添加到StringBuilder
,所以我不保持主窗体加载单行文本。
处理完成后,我将结果转储到richtext textbox
。我想根据我的关键词突出显示一些文字。我最终使用了一个字符串。查找每个单词的所有文本以突出显示它。我尝试使用一个线程来突出显示lambda表达式richbox.BeginInvoke的文本。线程工作正常,但在富文本框上占用句柄并且非常慢。
如何考虑50-100 MB的文本,逐行循环遍历richtext box
并突出显示其中的一些单词并具有可理解的性能?
此问题已从超级用户转移,因为其编程相关。 有一些建议的解决方案,例如: http://www.dotnetcurry.com/ShowArticle.aspx?ID=146 和 http://www.codeproject.com/Articles/4031/Background-Highlighting-with-the-RichTextBox-the-S ,但对于大文本来说,它们仍然效率低下。
foreach (string x in LArgs)
{
int len =0;
int index = 0;
int lastIndex=0;
output.Invoke(() => { len=output.Text.Length; });
output.Invoke(() => { lastIndex=output.Text.LastIndexOf(x); });
while (index < lastIndex)
{
output.Invoke(() => { output.Find(x, index, len, RichTextBoxFinds.None); });
output.Invoke(() => { this.output.SelectionBackColor = Color.Yellow; });
output.Invoke(() => { index = this.output.Text.IndexOf(x, index) + 1; });
}
}
我添加了库并使用了这段代码:
scintilla1.Text = output.Text;
StringBuilder conf = new StringBuilder();
conf.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
conf.AppendLine(@"<ScintillaNET>");
conf.AppendLine("<Language Name=\"log\">");
conf.AppendLine("<lexer LexerName=\"log\">");
conf.AppendLine("<Keywords List=\"0\">");
foreach (string x in LArgs)
{
conf.Append(x + " ");
}
//var
conf.AppendLine("</Keywords>");
conf.AppendLine(@"</lexer >");
conf.AppendLine(@"<Styles>");
conf.AppendLine(@"</Language>");
conf.AppendLine(@"</ScintillaNET>");
File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory+@"ScintillaNET.xml", conf.ToString());
scintilla1.Lexing.LexerLanguageMap["log"] = "cpp";
scintilla1.ConfigurationManager.CustomLocation = AppDomain.CurrentDomain.BaseDirectory + @"ScintillaNET.xml";
scintilla1.ConfigurationManager.Language = "log";
scintilla1.ConfigurationManager.Configure();
文本已加载但未突出显示我稍后在
添加的任何文字或文字答案 0 :(得分:1)