0

when you erase a coloured text. By default, the control sets the new entered text colour back to that was recently erased. how can you avoid that? do you need to check each character style before you type?

UPDATE:

I'm trying to set the text color like this.

SendMessage(hEdit, EM_SETSEL, start_pos, end_pos); //select text for coloring

        CHARFORMAT cf;
        memset( &cf, 0, sizeof cf );
        cf.cbSize = sizeof cf;
        cf.dwMask = CFM_COLOR;
        cf.crTextColor = RGB(255,0,0);
        SendMessage( hEdit , EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf);

        SendMessage(hEdit, EM_SETSEL, -1, 0 ); //deselect text
        cf.crTextColor = RGB(0,0,0); //reset colour
        SendMessage( hEdit , EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf); //set colour
cpx
  • 17,009
  • 20
  • 87
  • 142

1 Answers1

1

Your question is quite unclear. Wild stab at it: you lose all formatting when you assign the Text property. Be sure to use AppendText() instead. And to set the SelectionColor and SelectionBackColor properties back to what it was after colorizing any text so that newly entered text gets the preferred default colors.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • I set the color back to default (black) after changing the color (say, red). but at the run-time, when i try to erase that text (red) in the richedit, the default text color properties gets changed (to red) as well. – cpx Feb 17 '10 at 13:36
  • Yes, that's why I recommended restoring the SelectionColor/BackColor properties. – Hans Passant Feb 17 '10 at 13:48
  • but I don't know when to restore, does it send like a notify message to its parent that color property has changed? – cpx Feb 17 '10 at 14:14
  • You changed the colors, right? So you'll know when to change them back. After you used the changed colors. This is a bit too obvious, you really need to update your question with better info. – Hans Passant Feb 17 '10 at 14:18
  • When i restore the color back to default (black) after changing (say line 1 to red) it works, but if i type (in the line 1) again the colour changes back to red at the run-time. – cpx Feb 17 '10 at 14:31
  • I haven't checked the later versions but it seems like richedit control 2.0 is meant to work like this way. I tested it in windows wordpad and it is also implemented to work the same way. – cpx Feb 17 '10 at 19:32