Color change in Rich Edit Control

孤人 提交于 2019-12-08 12:39:01

问题


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:


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.



来源:https://stackoverflow.com/questions/2277939/color-change-in-rich-edit-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!