开发者

Color change in Rich Edit Control

when yo开发者_运维百科u 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜