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!

Coloured lines in a rich text box

Status
Not open for further replies.

exodus300

Programmer
Mar 22, 2002
262
AU
How can I make each line in a Rich Text Box (or a Memo) a different colour, so the contents could look something lke this:

Line 1 is RED
Line 2 is GREEN
Another RED line
A BLUE line [Thanks in advance|Hope I helped you]
Exodus300
[pc3]
 
Heh, I got it...

Code:
RichEdit1->SelAttributes->Color = clBlue;
RichEdit1->Lines->Add("A BLUE line");

The only problem is that if the user has hilighted some text in the box, that text changes colour and the new text remains black. The RichEdit is set to read-only (ReadOnly = true), but the user can still select text. How can I prevent that? [Thanks in advance|Hope I helped you]
Exodus300
[pc3]
 
to avoid selecting text try this:
void __fastcall TForm1::RichEdit1MouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
RichEdit1->SelLength = 0;
}
void __fastcall TForm1::RichEdit1KeyUp(TObject *Sender, WORD &Key,
TShiftState Shift)
{
RichEdit1->SelLength = 0;
}

see also this post from BTecho: thread101-449481
 
You can set the richedit->enabled to false.

You can still manipulate the text but the
text is inaccessible to the user.

depends on what you are useing the richedit for.
do you want to toggle enabled on or off. This may
be unfeasible.

tomcruz.net

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top