L
Luc Bolly
Hi all.
It's not new, but I cannot find a really good solution. The context: I grab
text lines from log files in a RichTextBox and I would like to mark with a
specific color some keyworks (e.g. the errors). I wrote a function (see
hereunder) that works correctly when the number of lines is small (a few
tenth), but this goes really really slow when the number of lines containing
the keywords grows (lets say 10.000 lines). Here is the code:
private void Colorify(System.Windows.Forms.RichTextBox oRTBox, string
sValue, System.Drawing.Color oColor) {
oRTBox.SuspendLayout();
int i = oRTBox.Find(sValue, 0, RichTextBoxFinds.NoHighlight |
RichTextBoxFinds.MatchCase);
int iValue = sValue.Length;
while( i >= 0 && bStopAction==false) {
Application.DoEvents();
oRTBox.Select(i,iValue);
oRTBox.SelectionColor = oColor;
oRTBox.SelectionFont = new Font(oRTBox.SelectionFont, FontStyle.Bold);
i = oRTBox.Find(sValue, i+iValue, RichTextBoxFinds.NoHighlight |
RichTextBoxFinds.MatchCase);
}
oRTBox.Select(0,0);
oRTBox.ResumeLayout();
}
If anyone has an idea to optimize the processing, I would hear it with a
great pleasure. Maybe using something else that the RichTextBox ...
Kind regards,
Luc
It's not new, but I cannot find a really good solution. The context: I grab
text lines from log files in a RichTextBox and I would like to mark with a
specific color some keyworks (e.g. the errors). I wrote a function (see
hereunder) that works correctly when the number of lines is small (a few
tenth), but this goes really really slow when the number of lines containing
the keywords grows (lets say 10.000 lines). Here is the code:
private void Colorify(System.Windows.Forms.RichTextBox oRTBox, string
sValue, System.Drawing.Color oColor) {
oRTBox.SuspendLayout();
int i = oRTBox.Find(sValue, 0, RichTextBoxFinds.NoHighlight |
RichTextBoxFinds.MatchCase);
int iValue = sValue.Length;
while( i >= 0 && bStopAction==false) {
Application.DoEvents();
oRTBox.Select(i,iValue);
oRTBox.SelectionColor = oColor;
oRTBox.SelectionFont = new Font(oRTBox.SelectionFont, FontStyle.Bold);
i = oRTBox.Find(sValue, i+iValue, RichTextBoxFinds.NoHighlight |
RichTextBoxFinds.MatchCase);
}
oRTBox.Select(0,0);
oRTBox.ResumeLayout();
}
If anyone has an idea to optimize the processing, I would hear it with a
great pleasure. Maybe using something else that the RichTextBox ...
Kind regards,
Luc