Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add different color text to rft control 1

Status
Not open for further replies.

hennep

Programmer
Dec 10, 2000
429
I want to add characters to an rtf control using different colors. When I change the color of the control all existing text is changed as well, how to avoid this ?

Hennep
 
Hi :)

Here are some snippet that will help

RichEdit1->SelStart=RichEdit1->Text.Length(); //or -1
RichEdit1->SelAttributes->Color=clOlive;
RichEdit1->SelText="red";

RichEdit1->SelStart=RichEdit1->Text.Length(); //or -1
RichEdit1->SelAttributes->Color=clBlue;
RichEdit1->SelText="blue";

//Set Color back
RichEdit1->SelAttributes->Color=clBlack;


and


TFontStyles FontStyle;

FontStyle << fsBold << fsItalic;

// Normal Red text
RichEdit1->SelAttributes->Color = clRed;
RichEdit1->Lines->Add(&quot;Some Normal Red Text&quot;);

// Bold, Italic, Purple text
FontStyle << fsBold << fsItalic;
RichEdit1->SelAttributes->Color = clPurple;
RichEdit1->SelAttributes->Style = FontStyle;
RichEdit1->Lines->Add(&quot;Some Bold, Italic, Purple Text&quot;);

// Normal Black text
FontStyle >> fsBold >> fsItalic;
RichEdit1->SelAttributes->Color = clBlack;
RichEdit1->SelAttributes->Style = FontStyle;
RichEdit1->Lines->Add(&quot;Some Normal Black Text&quot;);
 
You first sample was what I needed, I never though of using the SelText property to add text.

thank,
Hennie
 
SelText is used to insert text at any point in the
text. it will replace whatever is selected by the
string that you choose to insert. if there is no text selcted by the cursor, the position of the cursor
is where the new text is inserted. unless this is changed as in the code above where the SelStart property is used.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top