本文转自:http://blog.sina.com.cn/s/blog_6ff5d7300101129r.html

方法一:

步骤一:在Dlg类中增加一个类成员变量: CFont m_editFont;

注意:这里Font对象必须是类成员变量,不能是局部变量,否则会出现只改变了光标的大小,而不能改变字体的大小。

步骤二:在OnInitDialog方法中增加下列语句:

m_editFont.CreatePointFont(180, "宋体");

m_editPlace.SetFont(&m_editFont); // 设置新字体

方法二:

在OnInitDialog方法中增加下列语句也可以实现:

CFont* ptf=m_editPlace.GetFont(); // 得到原来的字体

LOGFONT lf;

ptf->GetLogFont(&lf);

lf.lfHeight = 20; // 改变字体高度

strcpy (lf.lfFaceName, "隶书"); // 改变字体名称

m_editFont.CreateFontIndirect(&lf);

m_editPlace.SetFont(&m_editFont); // 设置新字体

注意:If是个新的结构体变量,GetLogFont函数是实现将ptf中的LOGFONT结构体变量拷贝给If了,所以改变If不等于是改变ptf中的LOGFONT变量。所以下面必须加这两句来创建新的字体对象

m_editFont.CreateFontIndirect(&lf);

m_editPlace.SetFont(&m_editFont); // 设置新字体

posted on 2012-12-07 10:20  韦德·许  阅读(601)  评论(0编辑  收藏  举报