怎样改变RichEdit选中文本的背景色?

rdr 2006-12-13 04:40:30
搜索了一些信息,但是却不管用。
----------------------------
1 楼ccrun(老妖)(www.ccrun.com)回复于 2005-12-01 13:13:42 得分 90
::CHARFORMAT2 cf;
cf.cbSize = sizeof(cf);
cf.crBackColor = clRed; // 红色
cf.dwMask = CFM_BACKCOLOR;
SendMessage(RichEdit1->Handle, EM_SETCHARFORMAT, SCF_SELECTION, long(&cf));
2 楼constantine(飘遥的安吉儿)回复于 2005-12-01 13:25:01 得分 10
Richedit::CHARFORMAT2 Format ;
Format.cbSize = sizeof(Format);
Format.dwMask = CFM_BACKCOLOR;
Format.crBackColor =clRed;
RichEdit1->Perform(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&Format);
5 楼Dy_fish()回复于 2005-12-01 13:31:56 得分 0 谢谢2位 我刚试完老妖的代码 准备来揭帖 就发现了 constantine(飘遥的安吉儿) 的!哈 我又试了下
也是可以的 呵呵 可惜我只有100分 那还安先后吧 呵呵 要不我再(注册个)开一个贴给分
1 楼ccrun(老妖)(www.ccrun.com)回复于 2005-12-01 19:14:51 得分 100
Richedit::CHARFORMAT2 cf2;
cf2.cbSize = sizeof(cf2);
cf2.crTextColor = clRed; // 红色前景
cf2.dwMask = CFM_BACKCOLOR | CFM_COLOR; // 多加一个CFM_COLOR
cf2.crBackColor = clYellow; // 黄色背景
RichEdit1->Perform(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf2);
...全文
408 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
LiChenYue 2007-01-10
  • 打赏
  • 举报
回复
学习。
蒋晟 2007-01-09
  • 打赏
  • 举报
回复
http://msdn2.microsoft.com/en-us/library/51y8h3tk(VS.80).aspx
DentistryDoctor 2007-01-09
  • 打赏
  • 举报
回复
Perform?

CRichEditCtrl::SetSelectionCharFormat
自己填正确CHARFORMAT就可以了。
ReverseEngineering 2007-01-09
  • 打赏
  • 举报
回复
学习。
Kudeet 2006-12-13
  • 打赏
  • 举报
回复
你搜索到的代码应该没有问题,注意使用上的细节
Kudeet 2006-12-13
  • 打赏
  • 举报
回复
The following code is set text to bold:

m_ctrlRichEdit.GetSel(nStartChar, nEndChar);
CHARFORMAT cf;
cf.dwMask = CFM_STRIKEOUT|CFM_BOLD;
cf.dwEffects = CFE_BOLD;
m_ctrlRichEdit.SetSelectionCharFormat(cf);

First of all, you'll have to set the size field of the CHARFORMAT struct.
Second, you'll want to check the dwMask field, you don't have to set the
strikeout-flag in your case. Check the rest of the possible values for this
struct, and you'll be able to change the color.


For the background, you'll need CHARFORMAT2 and SendMessage to the control to set instead of SetSelectionCharFormat.
qiujian5628 2006-12-13
  • 打赏
  • 举报
回复
while (m_strContent.Find(m_strFind, nStartPos)!=-1)
{
nStartPos = m_strContent.Find(m_strFind, nStartPos);
nStopPos = nStartPos + m_strFind.GetLength();
m_edit.SetSel(nStartPos, nStopPos);

CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
m_edit.GetSelectionCharFormat(cf);

cf.crTextColor = 255;
cf.dwMask = CFM_COLOR;
if (cf.dwEffects & CFE_AUTOCOLOR)
cf.dwEffects -= CFE_AUTOCOLOR;

m_edit.SetSelectionCharFormat(cf);
nStartPos = nStopPos;
iFind++;
}

15,975

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧