jdl
jdl

Reputation: 6333

How to change the "FONT" for CEdit?

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);

Upvotes: 6

Views: 15100

Answers (2)

JTPonto
JTPonto

Reputation: 21

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);

Upvotes: 2

Jabberwocky
Jabberwocky

Reputation: 50912

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

Upvotes: 7

Related Questions