CRichEditCtrl *edit = ((CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT));
//设置字体
CHARFORMAT cf;
edit->GetSelectionCharFormat(cf);
cf.dwMask=CFM_BOLD|CFM_CHARSET|CFM_COLOR|CFM_FACE|CFM_ITALIC|CFM_SIZE|CFM_UNDERLINE|CFM_STRIKEOUT;
cf.crTextColor = RGB(255,0,0);//设置颜色
cf.yHeight =400;//设置高度 strcpy(cf.szFaceName ,_T("华文隶书"));//设置字体
edit->SetWordCharFormat(cf); CString str;
int nTextLength;
//要写的内容为ABCDEFG
str = "大家好";
//加入换行
str += "\r\n";
//获得文字的长度
nTextLength = edit->GetWindowTextLength();
//将光标放在文本最末
edit->SetSel(nTextLength, nTextLength);
//写入文本
edit->ReplaceSel(str);
//显示最后一行数据
edit->PostMessage(WM_VSCROLL, SB_BOTTOM,0);字体都生效了,就是字体颜色还是黑的
//设置字体
CHARFORMAT cf;
edit->GetSelectionCharFormat(cf);
cf.dwMask=CFM_BOLD|CFM_CHARSET|CFM_COLOR|CFM_FACE|CFM_ITALIC|CFM_SIZE|CFM_UNDERLINE|CFM_STRIKEOUT;
cf.crTextColor = RGB(255,0,0);//设置颜色
cf.yHeight =400;//设置高度 strcpy(cf.szFaceName ,_T("华文隶书"));//设置字体
edit->SetWordCharFormat(cf); CString str;
int nTextLength;
//要写的内容为ABCDEFG
str = "大家好";
//加入换行
str += "\r\n";
//获得文字的长度
nTextLength = edit->GetWindowTextLength();
//将光标放在文本最末
edit->SetSel(nTextLength, nTextLength);
//写入文本
edit->ReplaceSel(str);
//显示最后一行数据
edit->PostMessage(WM_VSCROLL, SB_BOTTOM,0);字体都生效了,就是字体颜色还是黑的
edit->SetSel(nTextLength, nTextLength);// 在这里加一行试试看:
edit->SetWordCharFormat(cf);//写入文本
edit->ReplaceSel(str);
edit->SetSel(nTextLength, nTextLength);// 在这里加一行试试看:
edit->SetSelectionCharFormat(cf);//写入文本
edit->ReplaceSel(str);
// TODO: Add your control notification handler code here
CRichEditCtrl *edit = ((CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT));
edit->SetSel(0,edit->GetWindowTextLength()); //设置字体
CHARFORMAT cf;
edit->GetSelectionCharFormat(cf);
cf.dwMask=CFM_BOLD|CFM_CHARSET|CFM_COLOR|CFM_FACE|CFM_ITALIC|CFM_SIZE|CFM_UNDERLINE|CFM_STRIKEOUT;
cf.crTextColor = RGB(255,0,0);//设置颜色
cf.yHeight =400;//设置高度
edit->SetSelectionCharFormat(cf);
edit->SetFocus();选择改变颜色,也是黑色,不知道怎么回事
cf.dwEffects=CFE_ITALIC;
这是什么原因?有高手解答一下吗?