nikolajp Posted May 19, 2008 Posted May 19, 2008 I have made a RichText-box and made a function to highlight text in certain ways (bold etc.). So I can call this function with a text-variable and the function will higlight all instances of the text. There is more to it, but that is the basic function. I have a performance problem. It seems evertime i call this (setting the text properties) $oRP.SelStart = $markselstart - 1 $oRP.SelLength = $sizeof_searchtext $oRP.SelFontSize = $size to highlight, the text position is moved in the GUI to the place the text is. And I do this for many instances of text, so the text GUI will moved up and down until it is finished. This takes 1-4 seconds depending on how large the file is (and how many texts are to be highlighted). I think the moving around is using ressources. My question is - Is there a faster way to make this highlighting? Can I avoid the GUI moving the text-position when setting the text properties? Here it is: CODE Func highlight_text_inRTbox($searchtext, $action, $size,$number) $hitstring = $orp.text ;check if match is at the end of file. if so add a space so the highlighting can have an end point. ;if not every tekst following will be marked. ;sizeofhits-string $sizeof_searchtext=stringlen($searchtext) $string_in_end = StringRight($hitstring,$sizeof_searchtext) if($sizeof_searchtext<>0 AND $string_in_end=$searchtext) Then $orp.text = $hitstring & " " ;Search the Text and put startcharacter in array Dim $avArray[1] _ArrayDelete($avArray,0) Local $Counter = 0 While $counter < 1000 $Counter = $counter + 1 $result = StringInStr($hitstring, $searchtext,0,$counter) If($result = 0) Then _ArrayAdd($avArray,"end") ExitLoop Else _ArrayAdd($avArray,$result) Endif Wend ;number of times to loop through (depending on size of array) $loopingtimes=_ArraySize($avarray)-2 ;mark the text from searchresults in array $i = 1 While $i <= $loopingtimes If($avArray[$i]="end") Then ExitLoop Else $markselstart = $avarray[$i] Endif $oRP.SelStart = $markselstart - 1 $oRP.SelLength = $sizeof_searchtext $oRP.SelFontSize = $size if($action="colorredbold") Then $oRP.SelBold = True $oRP.SelColor=0x0000ff EndIf if($action="colorbluebold") Then $oRP.SelBold = True $oRP.SelColor=0xff0000 EndIf if($action="bold") Then $oRP.SelBold = True EndIf if($action="underline") Then $oRP.SelUnderline = True EndIf $i=$i+1 WEnd EndFunc
nikolajp Posted May 23, 2008 Author Posted May 23, 2008 Anyone with experience in RichTextBox text highlighting?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now