设置字体和颜色以编辑框文本 [英] Setting font and color to edit box text

查看:119
本文介绍了设置字体和颜色以编辑框文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了获得下面代码的字体对话框

 CFontDialog dlg;
if(dlg.DoModal()== IDOK)
{
//获取字体的GetCurrentFont()
//Getcolor()获取用户选择的颜色
//SetFont()可用于设置字体
} 


所以在这里,我的问题是可以使用哪个函数将颜色设置为用户选择的文本.

解决方案

看看文章在CEdit和CStatic中使用颜色 [ LOGFONT lf; memset(& lf, 0 sizeof (LOGFONT)); lf.lfHeight = 16 ; _tcsncpy_s(lf.lfFaceName,LF_FACESIZE,_T(" ),CFontDialog dlg; if(dlg.DoModal()==IDOK) { //GetCurrentFont() for font //Getcolor() gets color choosed by user //SetFont() can be used to setting the font }


so here my question is which function can be used to set the color to the text which is opted by the user.

解决方案

Take a look at the article Using colors in CEdit and CStatic[^], it would seem to be what you need.


You could do something like this to set the fonts:

LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = 16;
_tcsncpy_s(lf.lfFaceName, LF_FACESIZE, _T("Arial"), 7);
HFONT hFont = ::CreateFontIndirect(&lf);
CFont* pfont = CFont::FromHandle(hFont);
m_wndEditBox.SetFont(pFont);



You can also override the OnCtlColor function...


这篇关于设置字体和颜色以编辑框文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆