How can I change the color of certain characters i

2019-02-26 06:08发布

问题:

I'm doing a Delphi 7 project where I have to let a user enter in a number (Layers going down) to build a Christmas tree, but I also need to display the output as * (stars). I am having a problem editing a certain line of stars in the TRichEdit to make the color change randomly just like a real Christmas tree shines.

回答1:

Formatting in rich edit controls works by first selecting text, then applying formatting to that selection.

Select the text with the SelStart and SelLength properties.

Apply formatting with the SelAttributes property, for example SelAttributes.Color := clRed;.