?
Solved

RichEdit font problem

Posted on 2002-04-28
3
Medium Priority
?
735 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
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

807 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