如何更改CEdit的“FONT”?

时间:2012-03-29 23:22:45

标签: visual-c++ mfc

如何调整以下“字体”:(已解决)

fontSize 40
BOLD
Italicized 

由于


以下失败:(现在有效)

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

2 个答案:

答案 0 :(得分:6)

只要您的编辑控件仍然存在,请务必不要delete myFont

答案 1 :(得分:0)

这就是我所做的,它为我运行:

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