Rich Edit 控件中的颜色更改 [英] Color change in Rich Edit Control

查看:19
本文介绍了Rich Edit 控件中的颜色更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您擦除彩色文本时.默认情况下,控件将新输入的文本颜色设置回最近擦除的颜色.你怎么能避免呢?打字前需要检查每个字符的样式吗?

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?

更新:

我正在尝试像这样设置文本颜色.

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

推荐答案

你的问题很不清楚.疯狂尝试:当您分配 Text 属性时,您会丢失所有格式.请务必改用 AppendText().并将 SelectionColor 和 SelectionBackColor 属性设置回为任何文本着色后的状态,以便新输入的文本获得首选的默认颜色.

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.

这篇关于Rich Edit 控件中的颜色更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆