我在程序里头,Rich Edit contrl的作用是根据要求显示我要显示的字符,而且字符格式不一样的,比如说,如何实现以下功能?
按一下button,就显示“这是第一次”,其中字体为 五号,颜色 红色;
再按一下button,就显示“这是第二次”,字体为 六号,颜色为 绿色。
类似的功能,该怎么实现???
按一下button,就显示“这是第一次”,其中字体为 五号,颜色 红色;
再按一下button,就显示“这是第二次”,字体为 六号,颜色为 绿色。
类似的功能,该怎么实现???
The CHARFORMAT structure contains information about character formatting in a rich edit control.
void CMy111Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
CHARFORMAT cf;
CString str=_T("这是第一次!");
CRichEditCtrl *MyRich=(CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT1);
if(flag == 0)
{
cf.crTextColor=RGB(255,0,0);
cf.yHeight = 200;//字体大小
}
else
{
cf.crTextColor=RGB(0,255,0);
cf.yHeight = 300;
}
cf.dwEffects=CFM_BOLD;
MyRich->SetDefaultCharFormat(cf);
MyRich->SetSel(0,MyRich->LineIndex(1));
MyRich->ReplaceSel(str);
flag = 1;
}
别忘了IDC_RICHEDIT1.
我加了AfxInitRichEdit();就可以显示了,真郁闷!
快考试了,我只能这样简单地写一下,希望你能满意!
void CMy111Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
CHARFORMAT cf;
CString str=_T("这是第一次!\xd\xa");
CRichEditCtrl *MyRich=(CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT1);
cf.dwEffects=CFM_BOLD;
if(flag == 0)
{
cf.crTextColor=RGB(255,0,0);
cf.yHeight = 200;
}
else
{
cf.crTextColor=RGB(0,0,255);
cf.yHeight = 300;
}
MyRich->SetSelectionCharFormat(cf);//应该这样,不好意思
MyRich->ReplaceSel(str);
flag = 1;
}
void CMy111Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
CHARFORMAT cf;
CString str;
CRichEditCtrl *MyRich=(CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT1);
cf.dwEffects=CFM_BOLD;
if(flag == 0)
{
cf.crTextColor=RGB(255,0,0);
cf.yHeight = 200;
str=_T("这是第一次!\xd\xa");
}
else
{
cf.crTextColor=RGB(0,0,255);
cf.yHeight = 300;
str=_T("这是第二次!\xd\xa");
}
MyRich->SetSelectionCharFormat(cf);
MyRich->ReplaceSel(str);
flag = 1;
}
void CMy111Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
CHARFORMAT cf;
CString str;
CRichEditCtrl *MyRich=(CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT1);
cf.dwEffects=CFM_BOLD;
if(flag == 0)
{
cf.crTextColor=RGB(255,0,0);
cf.yHeight = 200;
str=_T("这是第一次!\xd\xa");
}
else
{
cf.crTextColor=RGB(0,0,255);
cf.yHeight = 300;
str=_T("这是第二次!\xd\xa");
}
MyRich->SetSelectionCharFormat(cf);
MyRich->ReplaceSel(str);
flag = 1;
}