orange has asked for the wisdom of the Perl Monks concerning the following question:
use Win32::GUI; use warnings; use strict; my $Win = new Win32::GUI::Window( -left => 3, -top => 5, -width => 640, -height => 480, -name => "Win", ); $Win->Show(); my $font = Win32::GUI::Font->new( -name => "Courier New", -size => 12, ); $Win->AddButton( -text => "Run", -name => "Button1", -left => 23, -top => 10, -width => 56, -height => 36, -foreground => 0, ); my $RichText = $Win->AddRichEdit( -text => "", -name => "RichText_Output", # OutPut Rich Text -left => 41, -top => 91, -width => 580, -height => 313, -multiline => 1, -vscroll => 1, ); $RichText->SetLimitText(4194304); Win32::GUI::Dialog(); sub Win_Terminate { return -1; } sub Button1_Click { my $file = "bigfile.txt"; my $onelineOfText; my @ptrns; my $outString; open(MYFILE, $file) || die; my @a = <MYFILE>; chomp @a; my $PATTERN = 'be'; for (@a) { $onelineOfText = $_; @ptrns = $onelineOfText =~ m/$PATTERN/g; if($ptrns[0]) { $outString = $outString . "$onelineOfText\r\n"; } } # print the lines containing patterns to RichText: $RichText->SetSel(-1,-1); # Move insertion point to the end $RichText->ReplaceSel($outString); #Insert at the insertion point # now the coloring process of just the matches: my $OutStrng = $RichText->Text(); #get the contents of RichText my @pstn; my $flag = 1; #get the positions of the beginning and end of every match: #and store them in a continious array @pstn while ($flag) { if($OutStrng =~ /$PATTERN/g){ push @pstn, $-[0]; push @pstn, $+[0]; } else {last} } my $x = 0; my $lng = $#pstn / 2; for(0..$lng){ $RichText -> SetSel($pstn[$x],$pstn[$x+1]); $RichText -> SetCharFormat( -color => "#FF0000"); $x = $x + 2; }; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: coloring text in RichEdit takes long time
by BrowserUk (Patriarch) on Apr 18, 2008 at 14:45 UTC | |
|
Re: coloring text in RichEdit takes long time
by tachyon-II (Chaplain) on Apr 18, 2008 at 15:47 UTC |