0
votes

I'm working with MFC Aplication in Visual Studio 2013 and i want to format a variable CString to appear in columns in a edit control box.

I already add a variable CString to the edit control box, but i can't format the text to appear in columns.

This is my code:

val=_T("column1 column2 column3") cycle for val.Format(val+_T("%-15ls%-20s%-15ls"),val1,val2,val3); val = val + _T("\r\n"); end of cicle for

That code is in a For cycle where val1,val2 and val3 are CStrings variables and change in each iteration.

My result is this:

colum1 colum2 colum3 hello world transform ice cream hello google pizza my name is Ze transform ice cream

And i want:

colum1 colum2 colum3 hello world transform ice cream hello google pizza my name is Ze transform ice cream

can you help me?

2
You can only do this if the font used in the edit control is fixed pitch such as "Courier". - Jabberwocky
Thank you very much!!! You save my life. It worked. I changed the all font of the mfc aplication and it worked. It is possible to change only the font in the edit box? - Afonso

2 Answers

0
votes

Your font must be fixed pitch such as "Courier New".

To change the font of the edit box do this in OnInitDialog:

CEdit *pEdit = (CEdit*)GetDlgItem(IDC_EDIT1);
CFont *pf = pEdit->GetFont();
LOGFONT lf ;
pf->GetLogFont(&lf);
_tcscpy(lf.lfFaceName, _T("Courier New"));
m_Font.CreateFontIndirect(&lf);
pEdit->SetFont(&m_Font);

and put

CFont m_Font;

in the declaration of your dialog class.

0
votes

It seems not all controls are updated after set a Font. What style have you set for the CEdit control?

Try manually Update after SetFont(&mFont);

pEdit->Invalidate(); 
pEdit->UpdateWindow();

(I can not comment a comment above, so my comment to above is here)