Solved

RichEdit Run-Time Formatting?

Posted on 2002-07-22
7
897 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 34

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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 34

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 34

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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