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
Change font color, size, style, and back color of certain words inside a rich ed 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
21-Jun-04
Category
Reporting /Printing
Language
Delphi 3.x
Views
201
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

Do you want to have a nice looking rich edit?

Answer:

This procedure will search and change the attributes (font name, font size, font 
color, font style, and back color) of certain words inside a rich edit control.  
Try the example. 

1   type
2     TTextAttributes = record
3       Font: TFont;
4       BackColor: TColor;
5     end;
6     {..}
7   
8   procedure SetTextColor(oRichEdit: TRichEdit; sText: string; rAttributes:
9     TTextAttributes);
10  var
11    iPos: Integer;
12    iLen: Integer;
13  
14    Format: CHARFORMAT2;
15  begin
16    FillChar(Format, SizeOf(Format), 0);
17    Format.cbSize := SizeOf(Format);
18    Format.dwMask := CFM_BACKCOLOR;
19    Format.crBackColor := rAttributes.BackColor;
20  
21    iPos := 0;
22    iLen := Length(oRichEdit.Lines.Text);
23    iPos := oRichEdit.FindText(sText, iPos, iLen, []);
24  
25    while iPos <> -1 do
26    begin
27      oRichEdit.SelStart := iPos;
28      oRichEdit.SelLength := Length(sText);
29      oRichEdit.SelAttributes.Color := rAttributes.Font.Color;
30      oRichEdit.SelAttributes.Size := rAttributes.Font.Size;
31      oRichEdit.SelAttributes.Style := rAttributes.Font.Style;
32      oRichEdit.SelAttributes.Name := rAttributes.Font.Name;
33  
34      oRichEdit.Perform(EM_SETCHARFORMAT, SCF_SELECTION, Longint(@Format));
35  
36      iPos := oRichEdit.FindText(sText, iPos + Length(sText), iLen, []);
37    end;
38  end;
39  
40  Example: 
41  
42  var
43    rAttrib: TTextAttributes;
44  begin
45    rAttrib.Font := TFont.Create;
46    rAttrib.Font.Color := clWhite;
47    rAttrib.Font.Size := 16;
48    rAttrib.Font.Style := [fsBold];
49    rAttrib.BackColor := clRed;
50  
51    SetTextColor(RichEdit1, 'Delphi', rAttrib);
52  
53    //Change another word attributes.
54    rAttrib.Font.Color := clYellow;
55    rAttrib.Font.Size := 10;
56    rAttrib.Font.Style := [fsBold, fsItalic];
57    rAttrib.BackColor := clBlue;
58  
59    SetTextColor(RichEdit1, 'Is greate', rAttrib);
60  
61    rAttrib.Font.Free; //Now free the font.
62  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