如何在初始化中改变控件字体

z_jzhao 2008-05-30 12:42:52
请问各位,如何在对话框初始化时,就改变静态文本字体大小?有如下代码:放在命令按键中可实现改变字体大小,但是放在初始化BOOL TEST_Dlg::OnInitDialog()中,就不能实现改变字体大小,请问问题出在那里,怎样解决?,

CDC *pDC=GetDC();
CFont font;
font.CreateFont(
58,
15,
0, // angle of escapement
0, // base-line orientation angle
FW_BOLD, // font weight
FALSE, // italic attribute option
FALSE, // underline attribute option
0, // strikeout attribute option
ANSI_CHARSET, // character set identifier
OUT_DEFAULT_PRECIS, // output precision
CLIP_DEFAULT_PRECIS, // clipping precision
DEFAULT_QUALITY, // output quality
DEFAULT_PITCH | FF_SWISS, // pitch and family
_T("Arial") //
);

GetDlgItem(IDC_TITLE)->SetFont(&font); //静态文本框ID: IDC_TITLE
...全文
93 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
halibobo520 2008-06-02
  • 打赏
  • 举报
回复
只谢他们两个?
z_jzhao 2008-06-02
  • 打赏
  • 举报
回复
多谢1楼和2楼的提示!
halibobo520 2008-05-30
  • 打赏
  • 举报
回复

学习笔记12~添加字体
1.在类内添加字体对象:
CFont m_Font;//字体
2.初始化
m_Font.CreateFont(17, // nHeight // 建立字体
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_NORMAL, // nWeight
FALSE, // bItalic
FALSE, // bUnderline 下划线
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
_T("Arial")); // lpszFac //_T("宋体")

3.给控件添加该字体
m_List.SetFont(&m_Font);
GetDlgItem(IDC_LIST)->SetFont(&m_Font);
pingguowuai 2008-05-30
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 vocanicy 的回复:]
将你的font对象改成对话框的成员变量就可以了

因为你定义的是局部变量
在OnInitDialog返回的时候这个字体就不存在了
所以就没有效果



C/C++ code
m_sFont.CreateFont(
58,
15,
0, // angle of escapement
0, // base-line orientation angle
FW_BOLD, // font weight
FALSE, …
[/Quote]

楼主试下吧!
vocanicy 2008-05-30
  • 打赏
  • 举报
回复
将你的font对象改成对话框的成员变量就可以了

因为你定义的是局部变量
在OnInitDialog返回的时候这个字体就不存在了
所以就没有效果



m_sFont.CreateFont(
58,
15,
0, // angle of escapement
0, // base-line orientation angle
FW_BOLD, // font weight
FALSE, // italic attribute option
FALSE, // underline attribute option
0, // strikeout attribute option
ANSI_CHARSET, // character set identifier
OUT_DEFAULT_PRECIS, // output precision
CLIP_DEFAULT_PRECIS, // clipping precision
DEFAULT_QUALITY, // output quality
DEFAULT_PITCH | FF_SWISS, // pitch and family
_T("Arial") //
);

GetDlgItem(IDC_ST_SAMPLE)->SetFont(&m_sFont);

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧