我正在尝试更改编辑框控件的字体大小,但是它只是粗体是不会更改字体大小 [英] I'm trying to change the fontsize of a edit box control, but it just bold is does not change font size

查看:126
本文介绍了我正在尝试更改编辑框控件的字体大小,但是它只是粗体是不会更改字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改对话框控件编辑框的字体大小,但是它只是将编辑框的字体加粗,并且不更改字体和字体样式的大小,而是将相同的代码与静态控件一起使用的原因是什么?代码是:-

CWnd* pWnd = GetDlgItem(IDC_EDIT1);
CFont font;
font.CreateFont(20,10,0,1,700,0,0,0,0,0,0,0,0,"Arial");
pWnd->SetFont(&font);


具有静态控制功能的相同代码

CWnd* pWnd = GetDlgItem(IDC_STATIC);
CFont font;
font.CreateFont(20,10,0,1,700,0,0,0,0,0,0,0,0,"Arial");
pWnd->SetFont(&font);


请任何人都可以帮助我...:rose:

解决方案

您知道吗(对于MM_TEXT映射模式,您可以使用以下公式为具有指定磅值的字体指定高度:

lfHeight = -MulDiv(PointSize,GetDeviceCaps(hDC,LOGPIXELSY),72);


?
例如,如果您的映射模式是MM_TEXT(默认设置),并且LOGPIXELSY值是96,那么您必须将-27(大约)指定为nHeight参数(CreateFont)以获得20个像素的高度字体.
:)


我认为您需要通过WM_SETFONT消息告诉编辑控件.可以在此处 [


The same code with static control works

CWnd* pWnd = GetDlgItem(IDC_STATIC);
CFont font;
font.CreateFont(20,10,0,1,700,0,0,0,0,0,0,0,0,"Arial");
pWnd->SetFont(&font);


Please Any one can help me...:rose:

解决方案

Are you aware of (MSDN):

For the MM_TEXT mapping mode, you can use the following formula to specify a height for a font with a specified point size:

lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);


?
If, for instance, your mapping mode is MM_TEXT (the default), and the LOGPIXELSY value is 96, then you have to specify -27 (circa) as nHeight parameter (the first one of CreateFont) to obtain a 20-pixels height font.
:)


I think you need to tell the edit control via the WM_SETFONT message. More information may be found here[^].


这篇关于我正在尝试更改编辑框控件的字体大小,但是它只是粗体是不会更改字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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