Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the "FONT" for CEdit?

Tags:

visual-c++

mfc

How to adjust the "font" for the following:(solved)

fontSize 40
BOLD
Italicized 

Thanks


The following fails:(now works)

CFont *myFont = new CFont();
myFont->CreateFont( 40, 0, 0, 0, FW_HEAVY, true, false,
        0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
        FIXED_PITCH|FF_MODERN, _T("Courier New") );

CEdit *ed1 = new CEdit();
ed1->Create(WS_VISIBLE | WS_BORDER,CRect(200,100,500,140),this,16);
ed1->SetFont(myFont);
like image 523
jdl Avatar asked Mar 29 '12 23:03

jdl


Video Answer


2 Answers

Be sure not to delete myFont as long as your edit control is still around.

like image 110
Jabberwocky Avatar answered Oct 11 '22 22:10

Jabberwocky


Here what i did, and it run for me :

CFont m_Font;
CEdit m_EditBox
CClientDC dc(this);
int nFontSize = 40;
int nHeight = -((dc.GetDeviceCaps(LOGPIXELSY) * nFontSize) / 72);
m_Font.CreateFont(nHeight, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, DEFAULT_PITCH | FF_SWISS, _T("Courier New"));

// Create edit box
if (m_EditBox.Create(WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | ES_WANTRETURN | ES_READONLY, CRect(0, 0, 100, 100), this, 0x102) == FALSE) return FALSE;
// Set font
m_EditBox.SetFont(&m_Font, TRUE);
like image 25
JTPonto Avatar answered Oct 11 '22 22:10

JTPonto