?
Solved

RichEdit font problem

Posted on 2002-04-28
3
Medium Priority
?
730 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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

777 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