我做了一个两天的界面程序,发现当更改一个EDIT1里字体大小时,EDIT2里的字体全部都跟着更改了,之前输入到EDIT2里面的也都改了,怎么办?字体颜色也一样!谢谢各位!
我是用按钮调系统字体颜色来更改的.
详细:
void CChatDialog::OnBnClickedOk()
{
CString str, mes;
CString str1=CTime::GetCurrentTime().Format(_T("%H:%M:%S"));
GetDlgItem(IDC_EDIT1)->GetWindowText(str);
if(str.GetLength()<1)
{
MessageBox(_T("发送消息不能为空"));
return;
}
CEdit *pEditCtrl=(CEdit *)GetDlgItem(IDC_EDIT2);
pEditCtrl->GetWindowText(mes);
mes+=ShowID+_T(" ")+str1+_T("\r\n");
mes+=str+_T("\r\n\r\n");
pEditCtrl->SetWindowText(mes);
pEditCtrl->LineScroll(pEditCtrl->GetLineCount());
GetDlgItem(IDC_EDIT1)->SetWindowText(_T(""));
GetDlgItem(IDC_EDIT1)->SetFocus();
}void CChatDialog::OnBnClickedButton1()
{
CColorDialog ColorDlg(m_textcolor);
if(ColorDlg.DoModal()==IDOK)
{
m_textcolor = ColorDlg.GetColor();
Invalidate();
} // TODO: 在此添加控件通知处理程序代码
}void CChatDialog::OnBnClickedButton2()
{
CFont*tempfont =m_writemsg.GetFont();
LOGFONT logfont;
tempfont->GetLogFont(&logfont);
CFontDialog fontdlg(&logfont);
if(fontdlg.DoModal()==IDOK)
{
m_font.Detach();
LOGFONT temp;
fontdlg.GetCurrentFont(&temp);
m_font.CreateFontIndirectW(&temp);
m_writemsg.SetFont(&m_font);
m_showmsg.SetFont(&m_font);
// TODO: 在此添加控件通知处理程序代码
}
}HBRUSH CChatDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
pDC->SetTextColor(m_textcolor); // TODO: 在此更改 DC 的任何属性 // TODO: 如果默认的不是所需画笔,则返回另一个画笔
return hbr;
}
我是用按钮调系统字体颜色来更改的.
详细:
void CChatDialog::OnBnClickedOk()
{
CString str, mes;
CString str1=CTime::GetCurrentTime().Format(_T("%H:%M:%S"));
GetDlgItem(IDC_EDIT1)->GetWindowText(str);
if(str.GetLength()<1)
{
MessageBox(_T("发送消息不能为空"));
return;
}
CEdit *pEditCtrl=(CEdit *)GetDlgItem(IDC_EDIT2);
pEditCtrl->GetWindowText(mes);
mes+=ShowID+_T(" ")+str1+_T("\r\n");
mes+=str+_T("\r\n\r\n");
pEditCtrl->SetWindowText(mes);
pEditCtrl->LineScroll(pEditCtrl->GetLineCount());
GetDlgItem(IDC_EDIT1)->SetWindowText(_T(""));
GetDlgItem(IDC_EDIT1)->SetFocus();
}void CChatDialog::OnBnClickedButton1()
{
CColorDialog ColorDlg(m_textcolor);
if(ColorDlg.DoModal()==IDOK)
{
m_textcolor = ColorDlg.GetColor();
Invalidate();
} // TODO: 在此添加控件通知处理程序代码
}void CChatDialog::OnBnClickedButton2()
{
CFont*tempfont =m_writemsg.GetFont();
LOGFONT logfont;
tempfont->GetLogFont(&logfont);
CFontDialog fontdlg(&logfont);
if(fontdlg.DoModal()==IDOK)
{
m_font.Detach();
LOGFONT temp;
fontdlg.GetCurrentFont(&temp);
m_font.CreateFontIndirectW(&temp);
m_writemsg.SetFont(&m_font);
m_showmsg.SetFont(&m_font);
// TODO: 在此添加控件通知处理程序代码
}
}HBRUSH CChatDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
pDC->SetTextColor(m_textcolor); // TODO: 在此更改 DC 的任何属性 // TODO: 如果默认的不是所需画笔,则返回另一个画笔
return hbr;
}
你现在是对对话框更改字体
把所有控件的字体颜色都改了。应该先判断pWnd是否为IDC_EDIT1等,再做修改
HBRUSH CChatDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor == CTLCOLOR_DLG)
{
pDC->SetTextColor(m_textcolor);
} // TODO: 在此更改 DC 的任何属性 // TODO: 如果默认的不是所需画笔,则返回另一个画笔
return hbr;
}
bClicked=FALSE;当时这不是好的办法,治标不治本呵呵不过简单啊完成任务再说吧