ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Removed Areas > C / C++

Static Text Control Font Size

(1/2) > >>

Davidtheo:
Hi,

Can some one please tell me a easy way to make these to static text label controls in MFC, MS Visual Studio have a larger text font.

I would like.

IDC_Words to have a font size of 70.
IDC_Answer to have a font size of 50.

I have tried GetDlgItem(IDC_Word)->SetWindowTextW(); and IDC_Answer::FONTSIZE(50); but both do not work.

Thanks

Eóin:
I believe you would have to create your own font object and load it into the control. All I can offer is WTL based code, but the MFC equivilent may not differ all that much.


--- Code: C++ ---CFont font_fixedw_; ... if (CFont font = GetFont()){        CLogFont lf;                     if (font.GetLogFont(&lf))        {                lf.lfWidth = 6;                lf.lfPitchAndFamily = FIXED_PITCH;                lf.lfFaceName[0] = 0;                font_fixedw_.CreateFontIndirect(&lf);        }} CWindow wndControl = GetDlgItem(IDC_DESCRIPTION);wndControl.SetFont(font_fixedw_);
Hope it is of some help.

Davidtheo:
Hi

If I change your code to this I only get one error, which I am not sure on how to fix.


--- Code: C++ ---CFont font_fixedw_;...LOGFONT lf;lf.lfWidth = 6;lf.lfPitchAndFamily = FIXED_PITCH;lf.lfFaceName[0] = 0;font_fixedw_.CreateFontIndirect(&lf);        CWnd *wndControl = GetDlgItem(IDC_Word);wndControl.SetFont(font_fixedw_); //Error Error C2228: left of '.SetFont' must have class/struct/union

Eóin:
From your code I'd guess the last line should be wndControl->SetFont(font_fixedw_); as wndControl is declared as a CWnd pointer. But as I say, I'd guess :)

Davidtheo:
Hi,

I have tried these two lines in different ways including the ways below.


--- Code: C++ ---CWnd *wndControl = GetDlgItem(IDC_Word);wndControl.SetFont(font_fixedw_); CWnd wndControl = new CWind;wndControl = GetDlgItem(IDC_Word);wndControl.SetFont(font_fixedw_); CWnd wndControl = GetDlgItem(IDC_Word);wndControl.SetFont(font_fixedw_); CWnd *wndControl = GetDlgItem(IDC_Word);wndControl->SetFont(font_fixedw_);
All of them seem to give me a error. Not sure what to do now.

Navigation

[0] Message Index

[#] Next page

Go to full version