在mfc中用OnCtlColor改变文本编辑框中字体的颜色,显示不能类型转换,怎么办
展开全部
文本颜色和文本字体以及文本编辑框的背景色可以在父类的OnCtlColor中设置
HBRUSH CMFCDlgDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd->GetDlgCtrlID() == IDC_MYEDIT)
{
pDC->SetTextColor(RGB(0,0,255)); //设置字体颜色
pDC->SelectObject(&m_Font); //设置字体样式
//设置背景色
pDC->SetBkMode(TRANSPARENT);
return CreateSolidBrush(RGB(0,255,0));
}
return hbr;
}
==============
CFont m_EditFontTime;
//编辑框内容设置字体---------------------------------------
m_EditFontTime.CreateFont(120, 0, 0, 0, 700,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_SWISS, _T("楷体"));
CEdit *m_EditTime=(CEdit *)GetDlgItem(IDC_EDIT1);
m_EditTime->SetFont(&m_EditFontTime);
CFont m_EditFontTime;
//编辑框内容设置字体---------------------------------------
m_EditFontTime.CreateFont(120, 0, 0, 0, 700,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_SWISS, _T("楷体"));
CEdit *m_EditTime=(CEdit *)GetDlgItem(IDC_EDIT1);
m_EditTime->SetFont(&m_EditFontTime);
HBRUSH CMFCDlgDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd->GetDlgCtrlID() == IDC_MYEDIT)
{
pDC->SetTextColor(RGB(0,0,255)); //设置字体颜色
pDC->SelectObject(&m_Font); //设置字体样式
//设置背景色
pDC->SetBkMode(TRANSPARENT);
return CreateSolidBrush(RGB(0,255,0));
}
return hbr;
}
==============
CFont m_EditFontTime;
//编辑框内容设置字体---------------------------------------
m_EditFontTime.CreateFont(120, 0, 0, 0, 700,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_SWISS, _T("楷体"));
CEdit *m_EditTime=(CEdit *)GetDlgItem(IDC_EDIT1);
m_EditTime->SetFont(&m_EditFontTime);
CFont m_EditFontTime;
//编辑框内容设置字体---------------------------------------
m_EditFontTime.CreateFont(120, 0, 0, 0, 700,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_SWISS, _T("楷体"));
CEdit *m_EditTime=(CEdit *)GetDlgItem(IDC_EDIT1);
m_EditTime->SetFont(&m_EditFontTime);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询