Hi All, Seems RichEdit has been quite topical lately... so I've got another challenge...
Attached below is a short self contained script which displays two RichEdit controls. If you select a number of characters or words in the upper control, the returned hex values are coloured RED in the lower RichEdit control. This uses SetCharFormat( -color => "#FF0000"); However the RED still doesn't do it for me, neither does bold as the texts width increases. What I really want to do is colour the background, but only the characters being selected, similar to that of MS Word where you can colour text as though with a yellow high-lighter. In my application I have set the background of the RichEdit control to that of the window - i.e. -background => "#ECE9D8", (silver/grey). Is this possible with either the current version of RichEdit or by adding -class => RichEdit20A I've had a quick look at MSDN and PARAFORMAT2 - wShadingStyle but could not get it to work or if this is in fact what would control this behaviour. http://msdn.microsoft.com/library/default.asp?url=/library/en- us/shellcc/platform/commctls/richedit/richeditcontrols/richeditcontrolreference/richeditstructures/charformat2.asp Does anybody have any idea how to do this, or if its achievable? Cheers Chris Wearn # === CODE === # Win32::GUI::RichEdit test use Win32::GUI; $text = "The quick brown fox jumps over the lazy dog."; $textAsHex = ""; $Font = new Win32::GUI::Font( -name => "Courier New", -height => 11, ); $Window = new Win32::GUI::Window( -name => "Window", -text => "Win32::GUI - RichEdit GetSel", -width => 500, -height => 400, -left => 100, -top => 100, -font => $Font, -addstyle => WS_CLIPCHILDREN, ); $Textbox1 = $Window->AddRichEdit( -name => "Textbox1", -text => $text, -left => 5, -top => 5, -width => $Window->ScaleWidth-10, -height => 200, -autovscroll => 1, -align => 'left', -autohscroll => 0, ); $Textbox2 = $Window->AddRichEdit( -name => "Textbox2", -text => "", -left => 5, -top => 220, -width => $Window->ScaleWidth-10, -height => 200, -autovscroll => 1, -align => 'left', -autohscroll => 0, ); $Window->Show(); Win32::GUI::Dialog(); sub Textbox1_MouseDown { #============================= $textAsHex = ""; $Textbox2->Text(""); $Window->Update(); @chars = split(//,$text); foreach my $char (@chars) { $textAsHex .= " 0x" . (sprintf "%1x", ord($char)); } $textAsHex =~ s/^\s//; $textAsHex =~ s/0x0 //g; $textAsHex =~ s/0x0$//g; $Textbox2->Text($textAsHex); $Textbox2->SetSel(0,160); $Textbox2->SetCharFormat( -color => "#000000"); print "Mouse Down\n"; } sub Textbox1_MouseUp { #============================= my (@sel) = $Textbox1->GetSel(); print "Mouse Up - Selected - $sel[0] $sel[1]\n"; $tstart = $sel[0] * 5; $tend = $sel[1] * 5; print "Selecting $tstart $tend\n"; $Textbox2->SetSel($tstart,$tend); $Textbox2->SetCharFormat( -color => "#FF0000"); $Window->Update(); } sub Window_Terminate { return -1; }