8 个解决方案
#1
HBRUSH CMD5TestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor == CTLCOLOR_BTN || nCtlColor == CTLCOLOR_STATIC)
{
pDC->SetTextColor(RGB(0,0,255));
pDC->SetBkColor(RGB(210,108,0));
return hbr;
}
pDC->SetTextColor(RGB(0,0,255));
pDC->SetBkColor(RGB(210,0,108));
return hbr;
}
这是我写的,没问题的,ReadOnly也可以,你看看
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor == CTLCOLOR_BTN || nCtlColor == CTLCOLOR_STATIC)
{
pDC->SetTextColor(RGB(0,0,255));
pDC->SetBkColor(RGB(210,108,0));
return hbr;
}
pDC->SetTextColor(RGB(0,0,255));
pDC->SetBkColor(RGB(210,0,108));
return hbr;
}
这是我写的,没问题的,ReadOnly也可以,你看看
#2
在OnChar或EidtChange中处理,不允许修改内容.取消只读属性
#3
readonly后, edit control响应的不再是WM_CTLCOLOREDIT, 而是WM_CTLCOLORSTATIC
#4
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
if (pWnd->GetDlgCtrlID()==IDC_EDIT1) //获取某控件ID以实现对其操作
{
pDC->SetTextColor(RGB(255,0,0)); //改变控件字体颜色
pDC->SetBkColor(RGB(255,0,0)); //改变控背景色
}
return hbr;
}
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
if (pWnd->GetDlgCtrlID()==IDC_EDIT1) //获取某控件ID以实现对其操作
{
pDC->SetTextColor(RGB(255,0,0)); //改变控件字体颜色
pDC->SetBkColor(RGB(255,0,0)); //改变控背景色
}
return hbr;
}
#5
重载WM_CTLCOLORSTATIC或者按照shunruo说的,只能改变有文本的行的背景色,好像不能让整个Edit框背景色改变,文本的颜色是可以改变了。。
#6
return (HBRUSH)GetStockObject(WHITE_BRUSH);
#7
WM_DRAWITEM
#8
能让整个Edit框背景色改变,文本的颜色是可以改变了。。
----
Edit框的颜色可以用画刷刷:
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if (pWnd- >GetDlgCtrlID()==IDC_EDIT1)
{
pDC- >SetTextColor(RGB(255, 0, 0));
pDC- >SetBkColor(RGB(0, 0 , 0)); //不要把文字的颜色和文本背景颜色设置成相同的了,否则, 看不到文字了
HBRUSH brush = CreateSolidBrush(RGB(你想的颜色));
return brush;
}
return hbr;
}
----
Edit框的颜色可以用画刷刷:
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if (pWnd- >GetDlgCtrlID()==IDC_EDIT1)
{
pDC- >SetTextColor(RGB(255, 0, 0));
pDC- >SetBkColor(RGB(0, 0 , 0)); //不要把文字的颜色和文本背景颜色设置成相同的了,否则, 看不到文字了
HBRUSH brush = CreateSolidBrush(RGB(你想的颜色));
return brush;
}
return hbr;
}
#1
HBRUSH CMD5TestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor == CTLCOLOR_BTN || nCtlColor == CTLCOLOR_STATIC)
{
pDC->SetTextColor(RGB(0,0,255));
pDC->SetBkColor(RGB(210,108,0));
return hbr;
}
pDC->SetTextColor(RGB(0,0,255));
pDC->SetBkColor(RGB(210,0,108));
return hbr;
}
这是我写的,没问题的,ReadOnly也可以,你看看
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor == CTLCOLOR_BTN || nCtlColor == CTLCOLOR_STATIC)
{
pDC->SetTextColor(RGB(0,0,255));
pDC->SetBkColor(RGB(210,108,0));
return hbr;
}
pDC->SetTextColor(RGB(0,0,255));
pDC->SetBkColor(RGB(210,0,108));
return hbr;
}
这是我写的,没问题的,ReadOnly也可以,你看看
#2
在OnChar或EidtChange中处理,不允许修改内容.取消只读属性
#3
readonly后, edit control响应的不再是WM_CTLCOLOREDIT, 而是WM_CTLCOLORSTATIC
#4
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
if (pWnd->GetDlgCtrlID()==IDC_EDIT1) //获取某控件ID以实现对其操作
{
pDC->SetTextColor(RGB(255,0,0)); //改变控件字体颜色
pDC->SetBkColor(RGB(255,0,0)); //改变控背景色
}
return hbr;
}
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
if (pWnd->GetDlgCtrlID()==IDC_EDIT1) //获取某控件ID以实现对其操作
{
pDC->SetTextColor(RGB(255,0,0)); //改变控件字体颜色
pDC->SetBkColor(RGB(255,0,0)); //改变控背景色
}
return hbr;
}
#5
重载WM_CTLCOLORSTATIC或者按照shunruo说的,只能改变有文本的行的背景色,好像不能让整个Edit框背景色改变,文本的颜色是可以改变了。。
#6
return (HBRUSH)GetStockObject(WHITE_BRUSH);
#7
WM_DRAWITEM
#8
能让整个Edit框背景色改变,文本的颜色是可以改变了。。
----
Edit框的颜色可以用画刷刷:
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if (pWnd- >GetDlgCtrlID()==IDC_EDIT1)
{
pDC- >SetTextColor(RGB(255, 0, 0));
pDC- >SetBkColor(RGB(0, 0 , 0)); //不要把文字的颜色和文本背景颜色设置成相同的了,否则, 看不到文字了
HBRUSH brush = CreateSolidBrush(RGB(你想的颜色));
return brush;
}
return hbr;
}
----
Edit框的颜色可以用画刷刷:
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if (pWnd- >GetDlgCtrlID()==IDC_EDIT1)
{
pDC- >SetTextColor(RGB(255, 0, 0));
pDC- >SetBkColor(RGB(0, 0 , 0)); //不要把文字的颜色和文本背景颜色设置成相同的了,否则, 看不到文字了
HBRUSH brush = CreateSolidBrush(RGB(你想的颜色));
return brush;
}
return hbr;
}