Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In my project I've 8 edit boxes and i need to set each box with different font. But my code is setting all the boxes single font<below code="">.. So how can i modify it??
void CTrail3Dlg::OnBnClickedButton1()
{
	UpdateData(TRUE);
	CFontDialog dlg;
	// get font for current dialog, just to fill in LOGFONT
	LOGFONT lf;
	CFont *pFont = GetFont();
	pFont->GetLogFont(&lf);

	if (dlg.DoModal()== IDOK)
	{
		dlg.GetCurrentFont(&lf);
		m_font.DeleteObject();
		m_font.CreateFontIndirect(&lf);
		GetDlgItem(IDC_EDIT1)->SetFont(&m_font);
		GetDlgItem(IDC_EDIT2)->SetFont(&m_font);
		GetDlgItem(IDC_EDIT3)->SetFont(&m_font);
		GetDlgItem(IDC_EDIT4)->SetFont(&m_font);
		GetDlgItem(IDC_EDIT5)->SetFont(&m_font);
		GetDlgItem(IDC_EDIT6)->SetFont(&m_font);
		GetDlgItem(IDC_EDIT7)->SetFont(&m_font);
		GetDlgItem(IDC_EDIT8)->SetFont(&m_font);
	}
	// TODO: Add your control notification handler code here
}
Posted

Technically possible :) :
C++
{
  enum { ctlCount = 8; }

  static const UINT suiID[ctlCount] = {
    IDC_EDIT1, IDC_EDIT2, IDC_EDIT3, IDC_EDIT4,
    IDC_EDIT5, IDC_EDIT6, IDC_EDIT7, IDC_EDIT8
  };

  static CFont scFont[ctlCount];

  for (int i = 0; i < ctlCount; i++) {
    CFontDialg dlg;
    if (IDOK == dlg.DoModal()) {
      LOGFONT lf = {0};
      dlg.GetCurrentFont(&lf);
      scFont[i].DeleteObject();
      scFont[i].CreateFontIndirect(&lf);
      CWnd* pcEdit(GetDlgItem(suiID[i]));
      if (pcEdit->GetSafeHwnd()) {
        pcEdit->SetFont(&scFont[i]);
      }
    }
  }
}
 
Share this answer
 
void CTrail3Dlg::OnEnChangeEdit1()
{
	e=(CEdit*)GetDlgItem(IDC_EDIT1);
	// TODO:  Add your control notification handler code here
}

e is a pointer of type CEDIT.

void CTrail3Dlg::OnBnClickedButton1()
{
UpdateData(TRUE);
CFontDialog dlg;
// get font for current dialog, just to fill in LOGFONT
LOGFONT lf;
CFont *pFont = GetFont();
pFont-&amp;gt;GetLogFont(&amp;amp;lf);

if (dlg.DoModal()== IDOK)
{
dlg.GetCurrentFont(&amp;amp;lf);
m_font.DeleteObject();
m_font.CreateFontIndirect(&amp;amp;lf);
e-&amp;gt;SetFont(&amp;amp;m_font);
}
}</pre>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900