|
-
May 22nd, 2004, 07:51 PM
#1
Thread Starter
Sleep mode
Find text in RTB is very slow ?[Resolved]
This method works but it's damn slow . It takes about 1 minute to colorize some keywords . I feel like there is a way to improve it and speed it up . Anyone has a solution or alternative method ?
VB Code:
Public Sub FindHighlight(ByVal Keywords As ArrayList, ByVal HighlightColor As Color)
Me.SuspendLayout()
Dim StartLooking As Integer = 0
Dim FoundAt As Integer
Dim SearchLength As Integer
For Each keyword As String In Keywords
SearchLength = keyword.Length
Application.DoEvents()
Do
FoundAt = Me.RichTextBox1.Find(keyword, StartLooking, RichTextBoxFinds.WholeWord)
If FoundAt > -1 Then Me.RichTextBox1.SelectionColor = HighlightColor
StartLooking = StartLooking + SearchLength
Loop While FoundAt > -1
SearchLength = 0
FoundAt = 0
StartLooking = 0
Next
Me.ResumeLayout()
End Sub
btw , I'll not go with threading now .It's my last option , I think
Thanks
Last edited by Pirate; May 23rd, 2004 at 10:30 AM.
-
May 23rd, 2004, 02:56 AM
#2
use Regex Pirate mate
it's great on Keywords , you can use the Index and Length properties on the Match to select / highlight / carry on to the next found item. it's about the fastest i've found for highlighting in RTF.
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
May 23rd, 2004, 08:22 AM
#3
Thread Starter
Sleep mode
Any example , demo .. I've never tried regex before
-
May 23rd, 2004, 10:12 AM
#4
a very simple example ( cuz it's sunday and we been having a family day ) ...
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim keywords() As String = {"public", "private", "void", "class", "string"}
For Each keyword As String In keywords
Dim rgx As New Regex(keyword & "\s*([^a-z,0-9]+)", RegexOptions.IgnoreCase)
Dim mCol As MatchCollection = rgx.Matches(rtfSyntax.Text)
For Each m As Match In mCol
rtfSyntax.Select(m.Index, m.Length)
rtfSyntax.SelectionColor = Color.Blue
Next
Next
End Sub
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
May 23rd, 2004, 10:22 AM
#5
Thread Starter
Sleep mode
God bless you and your family .
I got the idea and I can go on with my project .
-
May 23rd, 2004, 10:28 AM
#6
Fanatic Member
Great example. You should work up a small sample project and put it in the .Net Code Bank.
www.RealisticGraphics.net
Running VS.Net Enterprise & VB 6
Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML
MSN Messenger: kmsheff
-
May 23rd, 2004, 11:05 AM
#7
Thread Starter
Sleep mode
sysop , small glitch in the pattern applied !!
It extends the color to some chars like (# , () in tostring() function ) . It doesn't seem to be %100 accurate . And also , how can I make it differenciate between string and tostring (it colorize both).
-
May 23rd, 2004, 11:11 AM
#8
like i said , a basic example. you need to specify if you want spaces before / after a string with regex
\s+private\s+ would search for the word " private " with a space before and after it , but it will prevent you from finding all cases of the word ( eg: if you are at the begining or end of a row of text )
to search for the word but not allow chars before or after ( eg: privateW fails , wPrivate fails , private succeeds ) ...
PHP Code:
"\s*([^a-z,0-9]+)" & keyword & "\s*([^a-z,0-9]+)"
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
May 23rd, 2004, 02:38 PM
#9
Thread Starter
Sleep mode
Using keyword as a pattern works . Thanks for explanation though .
-
May 23rd, 2004, 04:14 PM
#10
Thread Starter
Sleep mode
PHP Code:
"\s" + keyword + "\s"
This works better , but I'm having trouble with comment lines . I don't want to highlight keywords in comments . How can I skip like this " # region " or " // private fields ...etc" ??
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
|