VC 如何获取一个控件内的字体
我在对话框上放了一个RichText控件,在打开字体对话框的时候,能自动获取该控件的字体,并显示!我该如何做呢?...
我在对话框上放了一个RichText控件,在打开字体对话框的时候,能自动获取该控件的字体,并显示!我该如何做呢?
展开
4个回答
2013-06-25
展开全部
呵呵,你的问题我前一阵子都遇到过。你是不是要在一个Dialog里放一个RichEdit和一个Button,点击这个Button弹出CFontDialog对话框?这样的话你可以在这个Button的单击事件里这样写,基本上跟“风火石”的差不多。
void CMyClass::OnButtonFont()
{
CHARFORMAT cf.
LOGFONT lf;
memset(&cf, 0, sizeof(CHARFORMAT));
memset(&lf, 0, sizeof(LOGFONT));
myRichEdit.GetDefaultCharFormat(cf);
//得到相关字体属性
BOOL bIsBold = cf.dwEffects & CFE_BOLD;
BOOL bIsItalic = cf.dwEffects & CFE_ITALIC;
BOOL bIsUnderline = cf.dwEffects & CFE_UNDERLINE;
BOOL bIsStrickout = cf.dwEffects & CFE_STRIKEOUT;
//设置属性
lf.lfCharSet = cf.bCharSet;
lf.lfHeight = cf.yHeight/15;
lf.lfPitchAndFamily = cf.bPitchAndFamily;
lf.lfItalic = bIsItalic;
lf.lfWeight = (bIsBold ? FW_BOLD : FW_NORMAL);
lf.lfUnderline = bIsUnderline;
lf.lfStrikeOut = bIsStrickout;
strcpy(lf.lfFaceName, cf.szFaceName);
CFontDialog dlg(&lf);
dlg.m_cf.rgbColors = cf.crTextColor;
//以上就是自动获得RichEdit字体属性,并且打开字体对话框时照此初始化
if (dlg.DoModal() == IDOK)
{
//获得所选的字体属性,如字体、颜色、大小等
dlg.GetCharFormat(cf);
//设置输入框内所有字符的字体,包括已经输入的和将要输入的字符
myRichEdit.SetDefaultCharFormat(cf);
//如果要为选中的内容或者将要输入的内容设置字体,就参考“风火石”的答案
}
}
void CMyClass::OnButtonFont()
{
CHARFORMAT cf.
LOGFONT lf;
memset(&cf, 0, sizeof(CHARFORMAT));
memset(&lf, 0, sizeof(LOGFONT));
myRichEdit.GetDefaultCharFormat(cf);
//得到相关字体属性
BOOL bIsBold = cf.dwEffects & CFE_BOLD;
BOOL bIsItalic = cf.dwEffects & CFE_ITALIC;
BOOL bIsUnderline = cf.dwEffects & CFE_UNDERLINE;
BOOL bIsStrickout = cf.dwEffects & CFE_STRIKEOUT;
//设置属性
lf.lfCharSet = cf.bCharSet;
lf.lfHeight = cf.yHeight/15;
lf.lfPitchAndFamily = cf.bPitchAndFamily;
lf.lfItalic = bIsItalic;
lf.lfWeight = (bIsBold ? FW_BOLD : FW_NORMAL);
lf.lfUnderline = bIsUnderline;
lf.lfStrikeOut = bIsStrickout;
strcpy(lf.lfFaceName, cf.szFaceName);
CFontDialog dlg(&lf);
dlg.m_cf.rgbColors = cf.crTextColor;
//以上就是自动获得RichEdit字体属性,并且打开字体对话框时照此初始化
if (dlg.DoModal() == IDOK)
{
//获得所选的字体属性,如字体、颜色、大小等
dlg.GetCharFormat(cf);
//设置输入框内所有字符的字体,包括已经输入的和将要输入的字符
myRichEdit.SetDefaultCharFormat(cf);
//如果要为选中的内容或者将要输入的内容设置字体,就参考“风火石”的答案
}
}
2013-06-25
展开全部
void CMyRichEdit::OnSelectfont()
{
// TODO: Add your command handler code here
CHARFORMAT cf;
LOGFONT lf;
memset(&cf, 0, sizeof(CHARFORMAT));
memset(&lf, 0, sizeof(LOGFONT));
//判断是否选择了内容
BOOL m_bSelect = (GetSelectionType() != SEL_EMPTY) ? TRUE : FALSE;
if (m_bSelect)
{
GetSelectionCharFormat(cf);
}
else
{
GetDefaultCharFormat(cf);
}
//得到相关字体属性
BOOL bIsBold = cf.dwEffects & CFE_BOLD;
BOOL bIsItalic = cf.dwEffects & CFE_ITALIC;
BOOL bIsUnderline = cf.dwEffects & CFE_UNDERLINE;
BOOL bIsStrickout = cf.dwEffects & CFE_STRIKEOUT;
//设置属性
lf.lfCharSet = cf.bCharSet;
lf.lfHeight = cf.yHeight/15;
lf.lfPitchAndFamily = cf.bPitchAndFamily;
lf.lfItalic = bIsItalic;
lf.lfWeight = (bIsBold ? FW_BOLD : FW_NORMAL);
lf.lfUnderline = bIsUnderline;
lf.lfStrikeOut = bIsStrickout;
sprintf(lf.lfFaceName, cf.szFaceName);
CFontDialog dlg(&lf);
dlg.m_cf.rgbColors = cf.crTextColor;
if (dlg.DoModal() == IDOK)
{
dlg.GetCharFormat(cf);//获得所选字体的属性
if (m_bSelect)
SetSelectionCharFormat(cf); //为选定的内容设定所选字体
else
SetWordCharFormat(cf); //为将要输入的内容设定字体
}
}
{
// TODO: Add your command handler code here
CHARFORMAT cf;
LOGFONT lf;
memset(&cf, 0, sizeof(CHARFORMAT));
memset(&lf, 0, sizeof(LOGFONT));
//判断是否选择了内容
BOOL m_bSelect = (GetSelectionType() != SEL_EMPTY) ? TRUE : FALSE;
if (m_bSelect)
{
GetSelectionCharFormat(cf);
}
else
{
GetDefaultCharFormat(cf);
}
//得到相关字体属性
BOOL bIsBold = cf.dwEffects & CFE_BOLD;
BOOL bIsItalic = cf.dwEffects & CFE_ITALIC;
BOOL bIsUnderline = cf.dwEffects & CFE_UNDERLINE;
BOOL bIsStrickout = cf.dwEffects & CFE_STRIKEOUT;
//设置属性
lf.lfCharSet = cf.bCharSet;
lf.lfHeight = cf.yHeight/15;
lf.lfPitchAndFamily = cf.bPitchAndFamily;
lf.lfItalic = bIsItalic;
lf.lfWeight = (bIsBold ? FW_BOLD : FW_NORMAL);
lf.lfUnderline = bIsUnderline;
lf.lfStrikeOut = bIsStrickout;
sprintf(lf.lfFaceName, cf.szFaceName);
CFontDialog dlg(&lf);
dlg.m_cf.rgbColors = cf.crTextColor;
if (dlg.DoModal() == IDOK)
{
dlg.GetCharFormat(cf);//获得所选字体的属性
if (m_bSelect)
SetSelectionCharFormat(cf); //为选定的内容设定所选字体
else
SetWordCharFormat(cf); //为将要输入的内容设定字体
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-06-25
展开全部
你这个问题,我上次在 慧都控件网的技术文档里看到过,现在记不起了,你自己找找吧,这里是地址: http://www.evget.com/zh-CN/Info/List.aspx?key=47 而且最近他们还在搞免费的技术培训活动,你可以去看看,呵呵,免费的在线技术培训,地址是:
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
VC++里的(控件字体)是在背景窗体里设置的,在窗体里有(字体)选项按钮,非常方便实用。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询