Re: set TRichEdit text in bold

Posted by webmaster Guido on June 05, 2005

In Reply to: Re: set TRichEdit text in bold posted by joe90 on June 04, 2005

: So if I did the following:

: RichEdit1.SelAttributes.Style := [fsBold];
: RichEdit1.Lines.Add('This should be bold');
: RichEdit1.SelAttributes.Style := [];
: RichEdit1.Lines.Add('This should be regular');

: Should this work? I've tried it and well, it didn't - it all came out regular.

That's because SelAttributes starts working from the position where the text cursor is (also called the "insertion point"). You can set this with the SelStart property, like this:

RE.SelStart := Length(RE.Text); // Position cursor at end of RichEdit
RE.SelAttributes.Style := [fsBold];
RE.Lines.Add('This should be bold');
RE.SelAttributes.Style := [];
RE.Lines.Add('This should be regular');

webmaster Guido

Related Articles and Replies