MFC 请教怎样设置STATIC TEXT控件的字体大小和颜色
展开全部
设置字体:STASTIC TEXT 的ID改为IDC_STATIC1或其他唯一的ID
LOGFONT lf; //逻辑字体结构
::ZeroMemory(&lf,sizeof(lf));
lf.lfHeight = 40;
lf.lfWidth= 0;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = FW_BOLD;
lf.lfItalic = FALSE;
lf.lfUnderline = FALSE;
lf.lfStrikeOut= FALSE;
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN;
m_font1.CreateFontIndirect(&lf);
GetDlgItem(IDC_STATIC1)->SetFont(&m_font1);
设置颜色,为窗体添加OnCtlColor()函数,函数内填写下面代码
HBRUSH CInitial::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if (pWnd->GetDlgCtrlID() == IDC_STATIC1)
{
pDC->SetTextColor(RGB(255,0,0)); //蓝色
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
若满意请及时采纳,谢谢
LOGFONT lf; //逻辑字体结构
::ZeroMemory(&lf,sizeof(lf));
lf.lfHeight = 40;
lf.lfWidth= 0;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = FW_BOLD;
lf.lfItalic = FALSE;
lf.lfUnderline = FALSE;
lf.lfStrikeOut= FALSE;
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN;
m_font1.CreateFontIndirect(&lf);
GetDlgItem(IDC_STATIC1)->SetFont(&m_font1);
设置颜色,为窗体添加OnCtlColor()函数,函数内填写下面代码
HBRUSH CInitial::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if (pWnd->GetDlgCtrlID() == IDC_STATIC1)
{
pDC->SetTextColor(RGB(255,0,0)); //蓝色
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
若满意请及时采纳,谢谢
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询