编辑控件字体大小 [英] Edit Control font size

查看:93
本文介绍了编辑控件字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是这个vc ++的新手.我想在编辑控件中更改字体大小.这是我写的.它可以编译并运行,但不会更改字体大小.我的项目有一个编辑框和一个按钮.

I am new to this vc++. I want to change the font size in my edit control. Here is what I have written. It compiles and runs but does not change the font size. My project has one edit box and one button.

void CHebrewDlg::OnBnClickedNext()
{
	CEdit *pCtrl = (CEdit*) GetDlgItem(IDC_EDIT1);
	int static count = 0;
	wchar_t hebrew_ch[30] = 
           { L''א'', L''בּ'', L''ב'', L''ג'', L''ד'', L''ה'', L''ו'', L''ז'', L''ח'', L''ט'', 
	     L''י'', L''כּ'', L''כ'', L''ל'', L''מ'', L''נ'', L''ס'', L''ע'', L''פּ'', L''פ'',        
	     L''צ'', L''ק'', L''ר'', L''שׁ'', L''שׂ'', L''ת'' };

	LOGFONT lf;

	// clear out structure
	memset(&lf, 0, sizeof(LOGFONT)); 

	// request a 12-pixel-height font
	lf.lfHeight = 24;                

	// request a face name "Arial"
	_tcsncpy_s(lf.lfFaceName, LF_FACESIZE, _T("Arial"), 7);

	CFont font1;
	font1.CreateFontIndirect(&lf);  // create the font

	// CFont::operator HFONT automatically converts font1 from 
	// CFont* to HFONT.
	CFont* font2 = CFont::FromHandle(font1);

	//send to the target window
	SendMessage((UINT)pCtrl, WM_SETFONT, (WPARAM)font2);

	pCtrl->SetWindowTextW((CString)hebrew_ch[count]);
	count = ++count % 26;

 //Done with the font. Delete the font object.
 font1.DeleteObject();
}

推荐答案

您需要使CFont对象在控件的生命期内持久存在.在包含控件的窗口超出范围之前,请勿销毁它.
You need to make the CFont object persist for the life of the control. Do not destroy it until the window that contains the control goes out of scope.


这篇关于编辑控件字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆