C++ MFC

Moderators: Lundin
Number of threads: 3337
Number of posts: 9005

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
list box formatting Posted by pinkie on 15 Jul 2003 at 9:22 PM
i have a listbox in which text is to be displayed coloumn wise as shown below

1 ABCD 23 21 12
2 wwww 23 22 22

Right now i am storing each item of a row in a CString. And for displaying each row i use the following code

sDisplayStr.Format("%-10s%-10s%-10s%-10s%-10s%", sSlNo, sName, sText1, sText2, sText3);

where sSlNo = "1", sName = "ABCD", sText1 = "23", sText2 = "21", sText3 = "12"

I am not able to format the text properly. could anybody help me out please?
Also i want to know how do i change the font of the list box contents to courier new?

tnx
pinkie
Report
Re: list box formatting Posted by dwccgc on 16 Jul 2003 at 4:12 AM
You are formating the text properly, you just need to change the font. There are two ways to change the font in a list box.

1) Change the font for your whole application to "Courier New" by using the dialog properties option in your resource editor.

2) Use the
OnDrawItem method. See the below link for help.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_clistbox.3a3a.drawitem.asp

Just above and below the DrawText routine add the folloing code.

CFont Font;
CFont *pOldFont = NULL;
if (Font.CreatePointFont(120, _T("Courier New"), &dc))
{
    pOldFont = dc.SelectObject(&Font);
}
dc.DrawText(....);
if (pOldFont != NULL)
{
    dc.SelectObject(pOldFont);
}


: i have a listbox in which text is to be displayed coloumn wise as shown below
:
: 1 ABCD 23 21 12
: 2 wwww 23 22 22
:
: Right now i am storing each item of a row in a CString. And for displaying each row i use the following code
:
: sDisplayStr.Format("%-10s%-10s%-10s%-10s%-10s%", sSlNo, sName, sText1, sText2, sText3);
:
: where sSlNo = "1", sName = "ABCD", sText1 = "23", sText2 = "21", sText3 = "12"
:
: I am not able to format the text properly. could anybody help me out please?
: Also i want to know how do i change the font of the list box contents to courier new?
:
: tnx
: pinkie
:

Report
Re: list box formatting Posted by AsmGuru62 on 16 Jul 2003 at 6:38 AM
The 'Courier' will force you to scroll back and forth horizontally to see the whole record. When formatting use '\t' to separate the strings from each other and in the dialog designer make sure the checkbox "Use Tabstops" is ON.
CString strRecord;
CString strField1;
CString strField2;
CString strField3;

strRecord = strField1 + "\t" + strField2 + "\t" + strField3;
GetDlgItem (IDC_LIST1)->AddString (strRecord);




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.