mfc的小问题,Edit字体颜色,困扰一天了,能解决分全给!谢谢~~~~~~
问题很简单,2个Edit控件,IDC_EDIT,IDC_EDIT1,框里面是计体育比赛分数的,比如102,90等数字型字符串,另有+1,+2,+3的按钮,分别可以给2个框...
问题很简单,2个Edit控件,IDC_EDIT,IDC_EDIT1,框里面是计体育比赛分数的,比如102,90等数字型字符串,另有+1,+2,+3的按钮,分别可以给2个框加分1,2,3。
问题是:框里面的分数字体颜色,红,绿,黄分别表示领先,持平,落后状态,即当框1的数>框2的数时,框1分数红色,同时框2分数黄色,相等时,2个框字体都是绿色……。+1,+2,+3的按钮我自己实现了,运行没问题,但是字体颜色出问题了:比如当框1分数>框2时,框1能红色,但框2的颜色不能立即变成黄色,而是保持原来的,但用鼠标单击下框2时能变成黄色,或者单击+1,+2,+3(加之后仍小于框1)能变成黄色
下面是我字体颜色的源代码:
HBRUSH CLee2Dlg::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
UpdateData(1);
if(((CButton*)GetDlgItem(IDC_RADIO2))->GetCheck()==TRUE)
{
if(pWnd->GetDlgCtrlID()==IDC_EDIT)
pDC->SetBkColor(RGB(0,0,0));
if(pWnd->GetDlgCtrlID()==IDC_EDIT1)
pDC->SetBkColor(RGB(0,0,0));
int cp7,cp8;
cp7=atoi(m_edit);
cp8=atoi(m_edit1);
if(cp7>cp8)
{
if(pWnd->GetDlgCtrlID()==IDC_EDIT)
pDC->SetTextColor(RGB(255,0,0));
if(pWnd->GetDlgCtrlID()==IDC_EDIT1)
{pDC->SetTextColor(RGB(255,255,0));}
}
if(cp7==cp8)
{
if(pWnd->GetDlgCtrlID()==IDC_EDIT)
pDC->SetTextColor(RGB(0,255,0));
if(pWnd->GetDlgCtrlID()==IDC_EDIT1)
{pDC->SetTextColor(RGB(0,255,0));}
}
if(cp7<cp8)
{
if(pWnd->GetDlgCtrlID()==IDC_EDIT)
pDC->SetTextColor(RGB(255,255,0));
if(pWnd->GetDlgCtrlID()==IDC_EDIT1)
pDC->SetTextColor(RGB(255,0,0));
}
}
return hbr;
} 展开
问题是:框里面的分数字体颜色,红,绿,黄分别表示领先,持平,落后状态,即当框1的数>框2的数时,框1分数红色,同时框2分数黄色,相等时,2个框字体都是绿色……。+1,+2,+3的按钮我自己实现了,运行没问题,但是字体颜色出问题了:比如当框1分数>框2时,框1能红色,但框2的颜色不能立即变成黄色,而是保持原来的,但用鼠标单击下框2时能变成黄色,或者单击+1,+2,+3(加之后仍小于框1)能变成黄色
下面是我字体颜色的源代码:
HBRUSH CLee2Dlg::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
UpdateData(1);
if(((CButton*)GetDlgItem(IDC_RADIO2))->GetCheck()==TRUE)
{
if(pWnd->GetDlgCtrlID()==IDC_EDIT)
pDC->SetBkColor(RGB(0,0,0));
if(pWnd->GetDlgCtrlID()==IDC_EDIT1)
pDC->SetBkColor(RGB(0,0,0));
int cp7,cp8;
cp7=atoi(m_edit);
cp8=atoi(m_edit1);
if(cp7>cp8)
{
if(pWnd->GetDlgCtrlID()==IDC_EDIT)
pDC->SetTextColor(RGB(255,0,0));
if(pWnd->GetDlgCtrlID()==IDC_EDIT1)
{pDC->SetTextColor(RGB(255,255,0));}
}
if(cp7==cp8)
{
if(pWnd->GetDlgCtrlID()==IDC_EDIT)
pDC->SetTextColor(RGB(0,255,0));
if(pWnd->GetDlgCtrlID()==IDC_EDIT1)
{pDC->SetTextColor(RGB(0,255,0));}
}
if(cp7<cp8)
{
if(pWnd->GetDlgCtrlID()==IDC_EDIT)
pDC->SetTextColor(RGB(255,255,0));
if(pWnd->GetDlgCtrlID()==IDC_EDIT1)
pDC->SetTextColor(RGB(255,0,0));
}
}
return hbr;
} 展开
2个回答
展开全部
在.h 里面定义 CBrush m_brush;
在OnInitDialog(){
m_brush.CreateSolidBrush(RGB(0,255,0));
}
在HBRUSH CLee2Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
UpdateData(1);
if(((CButton*)GetDlgItem(IDC_RADIO2))->GetCheck()==TRUE)
{
if(pWnd->GetDlgCtrlID()==IDC_EDIT)
pDC->SetBkColor(RGB(0,0,0));
if(pWnd->GetDlgCtrlID()==IDC_EDIT1)
pDC->SetBkColor(RGB(0,0,0));
int cp7,cp8;
cp7=atoi(m_edit);
cp8=atoi(m_edit1);
if(cp7>cp8)
{
if(pWnd->GetDlgCtrlID()==IDC_EDIT)
pDC->SetTextColor(RGB(255,0,0));
if(pWnd->GetDlgCtrlID()==IDC_EDIT1)
{pDC->SetTextColor(RGB(255,255,0));}
}
if(cp7==cp8)
{
if(pWnd->GetDlgCtrlID()==IDC_EDIT)
pDC->SetTextColor(RGB(0,255,0));
if(pWnd->GetDlgCtrlID()==IDC_EDIT1)
{pDC->SetTextColor(RGB(0,255,0));}
}
if(cp7<cp8)
{
if(pWnd->GetDlgCtrlID()==IDC_EDIT)
pDC->SetTextColor(RGB(255,255,0));
if(pWnd->GetDlgCtrlID()==IDC_EDIT1)
pDC->SetTextColor(RGB(255,0,0));
}
return m_brush;
}
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
return hbr;
}//不行了再Hi我
在OnInitDialog(){
m_brush.CreateSolidBrush(RGB(0,255,0));
}
在HBRUSH CLee2Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
UpdateData(1);
if(((CButton*)GetDlgItem(IDC_RADIO2))->GetCheck()==TRUE)
{
if(pWnd->GetDlgCtrlID()==IDC_EDIT)
pDC->SetBkColor(RGB(0,0,0));
if(pWnd->GetDlgCtrlID()==IDC_EDIT1)
pDC->SetBkColor(RGB(0,0,0));
int cp7,cp8;
cp7=atoi(m_edit);
cp8=atoi(m_edit1);
if(cp7>cp8)
{
if(pWnd->GetDlgCtrlID()==IDC_EDIT)
pDC->SetTextColor(RGB(255,0,0));
if(pWnd->GetDlgCtrlID()==IDC_EDIT1)
{pDC->SetTextColor(RGB(255,255,0));}
}
if(cp7==cp8)
{
if(pWnd->GetDlgCtrlID()==IDC_EDIT)
pDC->SetTextColor(RGB(0,255,0));
if(pWnd->GetDlgCtrlID()==IDC_EDIT1)
{pDC->SetTextColor(RGB(0,255,0));}
}
if(cp7<cp8)
{
if(pWnd->GetDlgCtrlID()==IDC_EDIT)
pDC->SetTextColor(RGB(255,255,0));
if(pWnd->GetDlgCtrlID()==IDC_EDIT1)
pDC->SetTextColor(RGB(255,0,0));
}
return m_brush;
}
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
return hbr;
}//不行了再Hi我
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询