MFC CRichEdit改变指定区域的背景色和字体 .
2012-04-28 16:18
337 查看
注:m_richedit代表ID为IDC_RICHEDIT1的CRichEditCtrl控件的control类型的变量
1. 如何使用richedit添加AfxInitRichEdit();
CxxxApp::InitInstance()
{
AfxInitRichEdit();
.............
}
AfxInitRichEdit()功能:装载 RichEdit 1.0 Control (RICHED32.DLL).
2. 改变richedit指定区域的文字颜色及字体
CHARFORMAT cf;
ZeroMemory(&cf, sizeof(CHARFORMAT));
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_BOLD | CFM_COLOR | CFM_FACE |
CFM_ITALIC | CFM_SIZE | CFM_UNDERLINE;
cf.dwEffects = 0;
cf.yHeight = 12*12;//文字高度
cf.crTextColor = RGB(200, 100, 255); //文字颜色
strcpy(cf.szFaceName ,_T("隶书"));//设置字体
m_richedit.SetSel(1, 5); //设置处理区域
m_richedit.SetSelectionCharFormat(cf);
3. 改变richedit指定区域的文字背景颜色
CHARFORMAT2 cf; //声明为CHARFORMAT2结构,详细见MSDN
ZeroMemory(&cf, sizeof(CHARFORMAT2));
cf.cbSize = sizeof(CHARFORMAT2);
cf.dwMask = CFM_BACKCOLOR; cf.crBackColor=RGB(0, 255, 0); //背景颜色为绿色
m_richedit.SetSel(0, 2); //设置处理区域
m_richedit.SendMessage(EM_SETCHARFORMAT,SCF_SELECTION,(LPARAM)&cf);
4.只修改指定区域文字的背景颜色
先指定选择区域
m_richedit1.SetSel(0, 19); //设置处理区域
m_richedit1.HideSelection(FALSE, TRUE);//显示选择的区域背景 很重要
Changes the visibility of the selection.
Parameters
bHide
Indicates if the selection should be shown or hidden, TRUE to hide the selection.
bPerm
Indicates if this change in visibility for the selection should be permanent.
CRichEditCtrl object. For a brief description of this option, see SetOptions. You can use this function to set all the options for thisCRichEditCtrl object.
1. 如何使用richedit添加AfxInitRichEdit();
CxxxApp::InitInstance()
{
AfxInitRichEdit();
.............
}
AfxInitRichEdit()功能:装载 RichEdit 1.0 Control (RICHED32.DLL).
2. 改变richedit指定区域的文字颜色及字体
CHARFORMAT cf;
ZeroMemory(&cf, sizeof(CHARFORMAT));
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_BOLD | CFM_COLOR | CFM_FACE |
CFM_ITALIC | CFM_SIZE | CFM_UNDERLINE;
cf.dwEffects = 0;
cf.yHeight = 12*12;//文字高度
cf.crTextColor = RGB(200, 100, 255); //文字颜色
strcpy(cf.szFaceName ,_T("隶书"));//设置字体
m_richedit.SetSel(1, 5); //设置处理区域
m_richedit.SetSelectionCharFormat(cf);
3. 改变richedit指定区域的文字背景颜色
CHARFORMAT2 cf; //声明为CHARFORMAT2结构,详细见MSDN
ZeroMemory(&cf, sizeof(CHARFORMAT2));
cf.cbSize = sizeof(CHARFORMAT2);
cf.dwMask = CFM_BACKCOLOR; cf.crBackColor=RGB(0, 255, 0); //背景颜色为绿色
m_richedit.SetSel(0, 2); //设置处理区域
m_richedit.SendMessage(EM_SETCHARFORMAT,SCF_SELECTION,(LPARAM)&cf);
4.只修改指定区域文字的背景颜色
先指定选择区域
m_richedit1.SetSel(0, 19); //设置处理区域
m_richedit1.HideSelection(FALSE, TRUE);//显示选择的区域背景 很重要
Changes the visibility of the selection.
void HideSelection( BOOL bHide, BOOL bPerm ); |
bHide
Indicates if the selection should be shown or hidden, TRUE to hide the selection.
bPerm
Indicates if this change in visibility for the selection should be permanent.
Remarks
When bPerm is TRUE, it changes theECO_NOHIDESEL option for thisCRichEditCtrl object. For a brief description of this option, see SetOptions. You can use this function to set all the options for thisCRichEditCtrl object.
相关文章推荐
- MFC之CRichEdit改变指定区域的背景色和字体
- 改变MFC对话框背景色、控件内的字体颜色和背景色
- 如何改变CRichEdit字体颜色 vc
- MFC中改变字体及背景色
- 改变MFC对话框背景色、控件内的字体颜色和背景色
- 改变MFC对话框背景色、控件内的字体颜色和背景色
- 改变iOS中的导航栏和状态栏 的背景色和字体颜色
- MFC 可以设置背景色、字体、字体颜色、透明背景的 Static 静态文本控件
- MFC改变文本字体
- 关于VS2008下MFC中控件字体的改变
- 猎豹MFC--字体颜色对话框CFontDialog CColorDialog CRichEdit
- MFC Ribbon 改变Ribbon字体大小 Ribbon字体太小 模糊
- MFC OnPaint某一区域绘制背景色
- vc中改变对话框的背景色(MFC)
- MFC中可以设置字体颜色,背景色,前景色,是否透明
- MFC改变编辑框背景、字体、颜色等
- MFC改变对话框中的CEdit控件的背景色
- iOS UILabel改变指定字体大小和颜色
- MFC可以设置字体名称、大小、字体前景色、背景色的Static控件
- MFC对话框中改变对话框,Group Box, Static Text, Check Box, Edit Ctrl(disabled), Combo Box(disabled), Radio Button等控件背景色