CStstic控件更改字体大小使用“透明属性”问题 [英] CStstic control Change font size use "Transparent property" problem
问题描述
我创建了两个CStatic控件。一个属性设置为透明模式;另一个是正常的。更改字体大小后,一个是好的,它已更改,但设置的透明模式1的大小没有变化。
有人知道为什么吗?
谢谢。
/////////////////// ///////////////////////////////
//资源文件
LTEXT这是正常文本。,IDC_FONT2,7,119,303,21,WS_BORDER
LTEXT这包括透明。,IDC_FONT,7,7,306,21,WS_BORDER |不是WS_GROUP | WS_TABSTOP,WS_EX_TRANSPARENT
// FontTest.CPP
class CFontSizeDlg:public CDialogEx
{
public:
CStatic m_myFont;
CStatic m_myFont2;
}
// FontTest.CPP
无效CFontSizeDlg :: DoDataExchange(CDataExchange * pDX)
{
CDialogEx :: DoDataExchange(pDX);
DDX_Control(pDX,IDC_FONT,m_myFont);
DDX_Control(pDX,IDC_FONT2,m_myFont2);
}
无效CFontSizeDlg :: OnBnClickedButton2()
{
CFont hNewFont;
LOGFONT lf; //用于创建CFont。
CFont * currentFont = GetFont();
currentFont-> GetLogFont(&lf);
lf.lfHeight = 25;
lf.lfWidth = 10;
hNewFont.DeleteObject();
hNewFont.CreateFontIndirect(&lf); //创建字体。
//使用字体绘制控件。
m_myFont2.SetFont(&hNewFont);
m_myFont.SetFont(&hNewFont);
// hNewFont.Detach();
hNewFont.DeleteObject();
}
Hi,
I create two CStatic controls. One property is set to transparent mode; another one is normal. After I change font size, one is OK, it is changed, but the set transparent mode one is not changed in size.
Does anybody know why ?
Thanks.
//////////////////////////////////////////////////
// Resource File
LTEXT "This Is Normal Text.",IDC_FONT2,7,119,303,21,WS_BORDER
LTEXT "This Include Transparent.",IDC_FONT,7,7,306,21,WS_BORDER | NOT WS_GROUP | WS_TABSTOP,WS_EX_TRANSPARENT
// FontTest.CPP
class CFontSizeDlg : public CDialogEx
{
public:
CStatic m_myFont;
CStatic m_myFont2;
}
// FontTest.CPP
void CFontSizeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_FONT, m_myFont);
DDX_Control(pDX, IDC_FONT2, m_myFont2);
}
void CFontSizeDlg::OnBnClickedButton2()
{
CFont hNewFont;
LOGFONT lf; // Used to create the CFont.
CFont *currentFont = GetFont();
currentFont->GetLogFont(&lf);
lf.lfHeight = 25;
lf.lfWidth = 10;
hNewFont.DeleteObject();
hNewFont.CreateFontIndirect(&lf); // Create the font.
// Use the font to paint a control.
m_myFont2.SetFont(&hNewFont);
m_myFont.SetFont(&hNewFont);
// hNewFont.Detach();
hNewFont.DeleteObject();
}
推荐答案
你的OnBnClickedButton2中你不能DeleteObject();
( ) 方法。必须将CFont hNewFont;
变量定义为CFontSizeDlg
类的实例变量,并且当类为销毁。阅读此处 [ ^ ],尤其是评论栏目
You must notDeleteObject();
in your OnBnClickedButton2() method. TheCFont hNewFont;
variable must be defined as an instance variable of yourCFontSizeDlg
class and should be deleted when the class is destroyed. Read here[^], especially the comments section
这篇关于CStstic控件更改字体大小使用“透明属性”问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!