Solved

RichEdit Run-Time Formatting?

Posted on 2002-07-22
7
873 Views
Last Modified: 2013-11-22
I have a RichEdit component, and would like to set the default Tab spacing to 4 spaces... how do I do that?  And then, how would I instruct the program to insert a tab?

Then, I just need to know how to format data "on the fly".

Imagine the following "tagged" line :

[fsNormal]word01[tab]word02[fsBold]word03
[newline]
[fsNormal]word04[tab][color=red]word05[fsBold]word06

... hopfully, you can understand what i'm trying to say here. ;-)

You see, the following :

With RickEdit1 do begin
  Lines.Add('word01 word02 word03 etc. etc.');
end;

.. is all well and good, but, I need to insert tabs, and set color and font weight properties on the fly, for certain words.

Whenever I try to do this, with the Font.Style := [fsBold] thing, it sets the global property of the RichEdit component.

Can anyone here advise me?
0
Comment
Question by:nicey
  • 3
  • 2
  • 2
7 Comments
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7170877
You can do something like this:

with RichEdit1 do
begin
  Lines.Add('word01 word02 word03');
  SelStart := 0;
  SelLength := 6;
  SelAttributes.Style := [fsBold];
  SelStart := 7;
  SelLength := 6;
  SelAttributes.Color := clRed;
  SelStart := 14;
  SelLength := 6;
  SelAttributes.Style := [fsUnderline];
  SelAttributes.Color := clBlue;
end;



HTH
DragonSlayer.
0
 
LVL 33

Accepted Solution

by:
Slick812 earned 75 total points
ID: 7170921
hello nicey, you set the Selection of the Rich Edit and then adjust the selection properties to chsnge the Text that's selected. About the Tab stops, You can set a Paragraphs Tap stops with the Rich Edits Paragraph Properties, But It seems that the tab stops, ar used only in that paragraph, which in a TRichEdit defaults to just One Line, so you will need to set the Tabs for every line you want your Tab in. Also you say you want a Tab stop 4 spaces wide, but with which Font width? ?, the Tab stops are in Pixel widths. And to add tab stops use the #9 charater


procedure TForm1.button_NewTextClick(Sender: TObject);
begin
RichEdit1.Clear;
{there are 3 tab stops in this line}
RichEdit1.Lines.Add('word01'#9'word02'#9'word03'#9'word04 word05');
RichEdit1.SelStart := 7;
RichEdit1.SelLength := 6;
{where ever the Selection is, seems to be the Paragraph
(line) for the paragraph properties to be set}
RichEdit1.SelAttributes.Color := clAqua;
RichEdit1.SelAttributes.Name := 'Comic Sans MS';
RichEdit1.SelAttributes.Size := 16;
RichEdit1.SelAttributes.Style := [fsBold];
{the Richedit Paragraph seems to default to only one line
so you may need to set the Tabs for each line you use tabs in}
RichEdit1.Paragraph.Tab[0] := 60;
RichEdit1.Paragraph.Tab[1] := 60;
RichEdit1.Paragraph.Tab[2] := 60;
{these Tabs are for this single line}
RichEdit1.SelStart := 14;
RichEdit1.SelLength := 6;
RichEdit1.SelAttributes.Color := $0090FD;
RichEdit1.SelAttributes.Name := 'Times New Roman';
RichEdit1.SelAttributes.Size := 13;
RichEdit1.SelStart := 0;
RichEdit1.SelLength := 0;
end;


- - - - - - - - - - - -  - - - - - - -

you could use Canvas.TextWidth for the tabs

Canvas.Font := TheFontYouNeed;
RichEdit1.Paragraph.Tab[0] := Canvas.TextWidth('    ');
0
 
LVL 1

Author Comment

by:nicey
ID: 7172392
Ok, this is excellent.  Thank you both.

After I posted this question, I went back and played abit more (I don't think the documentation for RichEdit is all that great), and managed to come up with a FUNCTION, whereby I can pass parameters to, and then the text, I can then use that function call inside the Lines.Add(), but i'm falling over with selecting text.

How is the select text defined?  Is it from the top left, to the bottom right, in pixels or characters?

Or, is it line by line, from the first character, to the last character of that line... or, in pixels, line by line?

Once cleared up, I should have all I need to go about dancing with RichEdit.

Your input has been most informative so far.  Cheers.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 33

Expert Comment

by:Slick812
ID: 7172697
OK, with these

RichEdit1.SelStart := 7;
RichEdit1.SelLength := 6;

the values are in Charaters I.E.

RichEdit1.SelStart := 7;  
is 8 char from the begining of the text buffer for the Richedit, 0 being the First Charater

I believe all of this in in the Delphi Help for TRichedit--Properties--SelStart

and for

RichEdit1.SelLength := 6;
this is SIX charaters in Length
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7173263
Cheers :)
0
 
LVL 1

Author Comment

by:nicey
ID: 7175057
I don't think I could give the points to just one person here... is there a way I can split the points, or somthing like that?
0
 
LVL 33

Expert Comment

by:Slick812
ID: 7175492
you can award these points to one and then post another "Fake" question something like

Question -
"Points for Whoever"
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Virtuailstring tree compare node issue 14 116
FMX enumerated colours 2 98
how to center only a line in richedit? 4 56
How to define IfThen functions in one common unit? 4 49
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now