Hi!
I made a highlight script that checks the text and highlights matched words:
foreach (Match keyWordMatch in keyWords.Matches(txtIzvor.Text))
{
txtIzvor.Select(keyWordMatch.Index, keyWordMatch.Length);
txtIzvor.SelectionColor = System.Drawing.Color.Blue;
txtIzvor.SelectionStart = selPos;
txtIzvor.SelectionLength = 0;
}
but I have one problem: this check is ok but on every text changed event it checks all of the text so it bugs.
I used this script on document load. Can anybody help me make this script work for only the
line you are writing in
example:
if you write in line 1 it only checks line 1
Thanks!
Loading
StefanPosted Apr 6, 2009, 7:51 PM
To stop the flashing do this:
1. Add "using System.Runtime.InteropServices;" to your namespaces.
2. At the top of the class add "[DllImport("user32.dll")]
3. Under that add "public static extern bool LockWindowUpdate(IntPtr hWndLock);
4. Put the foreach loop you are using inside a "try" block. Instead of using a "catch" block, use a "finally" block.
5. Right before the foreach loop add "LockWindowUpdate(richtextbox1.Handle);"
6. Inside the "finally" block add "LockWindowUpdate(IntPtr.zero);"
This allows you to lock the rich text box's update, thus stopping the flashing.
I used this for a html editor I wrote, and it worked well. It won't do much for performance, however, since your still selecting all the text. I suggest you just play around with the selection start and length values.
blagoje ivanovicPosted Apr 5, 2009, 7:51 AM
That's the problem. For each change of color or something it runs text_changed event and it flashes and the process comes to 99. So basically, for every word it highlights it runs a text_changed event which checks the whole text again. I think it would be much easier for the processor if it checked only the current line.
StefanPosted Apr 4, 2009, 5:16 PM
You'll probably have to mess around with the selection start and length properties. Maybe you could store the previous start and length of the selection, then set the current selection to right after that.
When I asked what you meant by "it bugs", I meant what exactly is the problem. I'm guessing that when the document length starts getting longer the rich text box starts to "flash". Is this what's happening? If so I can tell you how to fix that, which is a lot easier than trying to select only the current line.
Please post back if the flashing is the issue. If not, post back and I'll try to help with selecting only the current line. Until then, I'll keep looking for a better solution.
blagoje ivanovicPosted Apr 4, 2009, 9:30 AM
blagoje ivanovicPosted Apr 2, 2009, 2:15 PM
I said that on every text_changed event (in RTB "txtIzvor") it checks the whole text so it takes a lot if you have a lot of text. I want it to check only the line you're writing in.
StefanPosted Apr 1, 2009, 5:36 PM