Solved

RichEdit Run-Time Formatting?

Posted on 2002-07-22
7
857 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

919 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