|
-
Jun 9th, 2006, 10:34 AM
#1
Thread Starter
Frenzied Member
is there a better way of doing this code...
I have this code:
Code:
private void markError(string errorString, System.Drawing.Color color)
{
int lastStrLoc = 0;
int strLoc = 0;
int errorStrLen = errorString.Length;
while((strLoc = rtbResult.Find(errorString, lastStrLoc, RichTextBoxFinds.None)) != -1)
{
lastStrLoc = strLoc + 1;
rtbResult.Select(strLoc, errorStrLen);
rtbResult.SelectionColor = color;
}
}
It basically looks for the errorString and changes its text to red. Is there a better way of doing this? When there is over 1000 of the target string, it takes quite a long time.
-
Jun 9th, 2006, 10:39 AM
#2
Re: is there a better way of doing this code...
Code:
private void markError(string errorString, System.Drawing.Color color)
{
rtbResult.Select(rtbResult.Text.IndexOf(errorString), errorString.Length);
rtbResult.SelectionColor = color;
}
-
Jun 9th, 2006, 11:14 AM
#3
Thread Starter
Frenzied Member
Re: is there a better way of doing this code...
thanks. I also just found out about rtf codes that change font color. I'll try both and see which way would be faster.
-
Jun 9th, 2006, 01:11 PM
#4
Re: is there a better way of doing this code...
A lot of the time will come from the text box being redrawn after each change. If you can lock the control from updating before doing the changes, and then unlock it, you should see an improvement.
Usually you would do this with BeginUpdate() and EndUpdate() functions, but the RichTextBox doesn't seem to have those .
Another solution using the Win32 API would be to import SendMessage, and send a WM_SETREDRAW with wParam = 1 to the handle of your richtextbox. Then, when you're done updating, send it again with wParam = 0.
HTH!
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|