Solved

RichEdit font problem

Posted on 2002-04-28
3
726 Views
Last Modified: 2013-12-03
Hi guys,

This is my problem... I have few procedures to change the font in a richedit component

procedure WriteA(s : string);
begin
  Form1.RichEdit1.Font.Name := 'Chess Merida';
  Form1.RichEdit1.Font.Size := 20;
  Form1.RichEdit1.Lines.Add(s);
end;

procedure WriteB(s: string);
begin
  Form1.RichEdit1.Font.Name := 'Courier New';
  Form1.RichEdit1.Font.Size := 10;
  Form1.RichEdit1.Lines.Add(s);
end;

and I use both procedures alternate over a richedit... i.e.

   WriteA('Hello');
   WriteB('GoodBye');

but... when I finish writing over the richtext,  the font assigned to each string is not respected. I mean, everything appears with the same font... Am I missing something?

best regards,
Manuel Lopez (lopem)
0
Comment
Question by:lopem
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
ID: 6975367
hi,
you need to change teh selattributes of it ,heres an example from my paq:

procedure TForm1.Button2Click(Sender: TObject);
var
Start,fin,SelStart,Selfin,
online : integer;
Begin
With RichEdit1 do
Begin
Lines.BeginUpdate;
Perform(EM_GETSEL,LongInt(@Start),LongInt(@fin));
online:=Perform(EM_LINEFROMCHAR,SelStart,0);
SelStart:= Perform(EM_LINEINDEX,online,0);
Selfin := SelStart+Length(Lines[online]);
Perform(EM_SETSEL,SelStart,Selfin );
Selattributes.color := clblue;
Selattributes.Name := 'Courier New';
Perform(EM_SETSEL, Start,fin );
lines.add('hello');
Lines.EndUpdate;
Setfocus;
end;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
Start,fin,SelStart,Selfin,
online : integer;
Begin
With RichEdit1 do
Begin
Lines.BeginUpdate;
Perform(EM_GETSEL,LongInt(@Start),LongInt(@fin));
online:=Perform(EM_LINEFROMCHAR,SelStart,0);
SelStart:= Perform(EM_LINEINDEX,online,0);
Selfin := SelStart+Length(Lines[online]);
Perform(EM_SETSEL,SelStart,Selfin );
Selattributes.color := clred;
Selattributes.size := 12;
Perform(EM_SETSEL, Start,fin );
Selattributes.Name := 'Arial';
lines.add('hello in red');
Lines.EndUpdate;
Setfocus;
end;
end;
0
 
LVL 3

Author Comment

by:lopem
ID: 6975377
Wow, InThe...

Thanks for the fast response... I just changed:

procedure WriteA(s : string);
begin
  Form1.RichEdit1.SelAttributes.Name := 'Chess Merida';
  Form1.RichEdit1.SelAttributes.Size := 20;
  Form1.RichEdit1.Lines.Add(s);
end;

procedure WriteB(s: string);
begin
  Form1.RichEdit1.SelAttributes.Name := 'Courier New';
  Form1.RichEdit1.SelAttributes.Size := 10;
  Form1.RichEdit1.Lines.Add(s);
end;

And everything worked now! Thanks a lot!

best regards,
Manuel Lopez (lopem)
0
 
LVL 17

Expert Comment

by:inthe
ID: 6975418
yep that'll work fine :)

also just note to say the example was from using trichedit98 (from torrys)
using trichedit98 you can change the background color of each line using selattributes.backcolor which normal richedit dont have.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question