Solved

RichEdit Run-Time Formatting?

Posted on 2002-07-22
7
838 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 33

Expert Comment

by:Slick812
Comment Utility
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
Comment Utility
Cheers :)
0
 
LVL 1

Author Comment

by:nicey
Comment Utility
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
Comment Utility
you can award these points to one and then post another "Fake" question something like

Question -
"Points for Whoever"
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

10 Experts available now in Live!

Get 1:1 Help Now