----------------------------
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);
7 个解决方案
#1
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++;
}
{
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++;
}
#2
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.
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.
#3
你搜索到的代码应该没有问题,注意使用上的细节
#4
学习。
#5
Perform?
CRichEditCtrl::SetSelectionCharFormat
自己填正确CHARFORMAT就可以了。
CRichEditCtrl::SetSelectionCharFormat
自己填正确CHARFORMAT就可以了。
#6
http://msdn2.microsoft.com/en-us/library/51y8h3tk(VS.80).aspx
#7
学习。
#1
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++;
}
{
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++;
}
#2
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.
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.
#3
你搜索到的代码应该没有问题,注意使用上的细节
#4
学习。
#5
Perform?
CRichEditCtrl::SetSelectionCharFormat
自己填正确CHARFORMAT就可以了。
CRichEditCtrl::SetSelectionCharFormat
自己填正确CHARFORMAT就可以了。
#6
http://msdn2.microsoft.com/en-us/library/51y8h3tk(VS.80).aspx
#7
学习。