Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to set the background colour of a word in a TRichEdit Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
05-Nov-02
Category
Reporting /Printing
Language
Delphi 3.x
Views
153
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I have a RichEdit control where my code outputs text into, formatting certain words 
or phrases with different font colors. This works fine, but I would also like to 
set the background of certain words to be different colors. MSWord allows this with 
the Highlight option, and I can copy and paste highlighted text from MSWord into my 
RichEdit control, so I have to assume that this is possible to do in code as well. 
Can anyone provide me with sample code or guidance on doing this in code?

Answer:

The version 1 richedit control introduced with Win95 did not have this ability and 
this version is what the TRichedit class was wrapped around. So it does not give 
you access to all the new abilities in the version 3 control you find on WinMe, 2K, 
and XP. You could delve into the murky depth of the API and send appropriate 
messages to the control:

uses
  richedit;

procedure TForm1.Button1Click(Sender: TObject);
var
  cf: TCharFormat2;
begin
  fillchar(cf, sizeof(cf), 0);
  cf.cbSize := sizeof(cf);
  cf.dwMask := CFM_BACKCOLOR;
  cf.crBackColor := ColorToRGB(clYellow);
  richedit1.Perform(EM_SETCHARFORMAT, SCF_SELECTION, lparam(@cf));
end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC