views:

187

answers:

1

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
+1  A: 

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
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.
Dave18
Yes, that's why I recommended restoring the SelectionColor/BackColor properties.
Hans Passant
but I don't know when to restore, does it send like a notify message to its parent that color property has changed?
Dave18
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
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.
Dave18
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.
Dave18