2

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.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
Jaryd
  • 21
  • 1
  • 2
  • Why bother using a RichEdit to make a "blinking christmas tree" when you could do it much more easily in a `TPaintBox`? – Warren P Aug 08 '11 at 23:39

1 Answers1

4

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;.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • How would you use it like this redout.selstart := 2; – Jaryd Aug 08 '11 at 07:24
  • SelStart refers to the character index rather than the line. Otherwise it would be impossible to format characters within a paragraph. – David Heffernan Aug 08 '11 at 07:27
  • How do you use the select Property does it select a line or a character – Jaryd Aug 08 '11 at 07:33
  • Um how do you make a range for the Selstart to select – Jaryd Aug 08 '11 at 07:34
  • 2
    I don't understand that question. Be precise. Also, read the vcl help for the properies I directed you towards. – David Heffernan Aug 08 '11 at 07:35
  • SelStart := 0; SelLength := 1; SelAttributes.Color := clRed; makes the first character red – David Heffernan Aug 08 '11 at 07:37
  • @David - +1, but I'm not 100% sure if the [SelAttributes](http://docwiki.embarcadero.com/VCL/en/ComCtrls.TCustomRichEdit.SelAttributes) were already introduced in Delphi 7. –  Aug 08 '11 at 10:40
  • 1
    @daemon_x In fact it was introduced long before D7. I think that without these properties, `TRichEdit` would be essentially useless and so I bet it was there from version 1. – David Heffernan Aug 08 '11 at 10:53
  • @David - that's right, maybe I missed them, because I remember I've been using directly [EM_SETCHARFORMAT](http://msdn.microsoft.com/en-us/library/bb774230%28v=VS.85%29.aspx). –  Aug 08 '11 at 11:03