通过FontComboBox更改MFC中CString的字体 [英] Changing font of a CString in MFC via FontComboBox

查看:287
本文介绍了通过FontComboBox更改MFC中CString的字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码遇到了一些问题。我想更改在程序主窗口中显示的单个CStringe的字体。在对话框中(通过菜单访问)我已经放置了MFC fontComboBox,我想从那里选择
字体。以下是一些代码块:

Hi, i have been having some problems with my code. I want to change the font of a single CStringe which is being displayed in the main window of the program. In the dialog box (accessed over a menu) i have put the MFC fontComboBox and I want to choose the font from there. Here are some code block:

//dialog .cpp document

void CTxtDlg :: OnOK()

void CTxtDlg::OnOK()

{
// TODO:在这里添加你的专门代码和/或调用基类

CMFCFontInfo * GetSelFont(); //从栏中获取字体

t = CTime :: GetCurrentTime()。格式(&%;%H:%M:%S"); //我希望以某种字体显示的字符串

CDialogEx :: OnOK();
}

{ // TODO: Add your specialized code here and/or call the base class CMFCFontInfo* GetSelFont(); //getting the font from the bar t=CTime::GetCurrentTime().Format("%H:%M:%S");//the string i want displayed in a certain font CDialogEx::OnOK(); }


//CFesbView .cpp doc

void CFesbView::OnEditTime()
{
	// TODO: Add your command handler code here
	CFesbDoc* pDoc = GetDocument();
	CTxtDlg dlg; 
	int response = dlg.DoModal(); 
	
	if (IDOK == response) 
	{
               pDoc->t = dlg.t;
	
	       Invalidate();
	}
}

有人可以帮我把这个字符串变成某种字体吗? :))

Could someone please help me get this string into a certain font.? :))

推荐答案

CString对象封装了文本字符串,对字体一无所知。  ;通常,您将在对话框控件中显示CString对象的文本,例如编辑框或静态控件(例如,CEdit或CStatic)。 要更改用于显示文本的字体
,您将更改控件使用的字体。 由于更改字体也可能会更改完全显示文本所需的像素数,因此可能需要调整控件的大小。

CString objects encapsulate text strings and don't know anything about fonts.  Ordinarily, you would display the text of a CString object in a dialog box control such as an edit box or a static ontrol (e.g., CEdit or CStatic).  To change the font used to display the text you would change the font used by the control.  And since changing the font could also change the number of pixels required to fully display the text it may be necessary to resize the control.

如果您自己绘制文本,则必须创建您要使用的字体,并将其选择到用于绘制文本的设备上下文中。

If you are drawing the text yourself then you must create the font that you want to use and select it into the device context used to draw the text.


这篇关于通过FontComboBox更改MFC中CString的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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