Click here to Skip to main content
15,920,217 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!

I'm trying to have tabs in my CButton/CMFCButton-labels:
C++
CMFCButton *but = (CMFCButton*)GetDlgItem(id);
CString label = _T("Test \t Test");
but->SetWindowText(label);

Instead of tha tab, a rectangle is displayed. I think I found something similar for CEdit-Controls, the problem was solved by using the define BS_MULTILINE.
This does not work for buttons...

I hope someone can help. Thanks ahead.
Posted
Updated 15-Aug-12 1:53am
v3
Comments
Richard MacCutchan 15-Aug-12 8:47am    
I do not think you can do this for most Window controls, as they expect the text to be pre-formatted, and do not take any action for special characters.
Jochen Arndt 15-Aug-12 11:46am    
I agree to Richard's comment. If you really need support for tab characters, you may derive a button class using owner draw to draw the label text.
Sergey Alexandrovich Kryukov 15-Aug-12 13:48pm    
Seems to me to be a correct solution -- I would up-vote it.
--SA
André Kraak 15-Aug-12 14:26pm    
The documentation (http://msdn.microsoft.com/en-us/library/windows/desktop/ms633546%28v=vs.85%29.aspx) specifically mentions this is not possible:

"The SetWindowText function does not expand tab characters (ASCII code 0x09). Tab characters are displayed as vertical bar (|) characters."
Sergey Alexandrovich Kryukov 15-Aug-12 17:24pm    
This would pass for a decent answer, too.
--SA

Moved my comment to this solution to get this question from the unanswered list. Credits should go to Jochen Arndt for the first correct answer.

The documentation[^] specifically mentions this is not possible:
Quote:
The SetWindowText function does not expand tab characters (ASCII code 0x09). Tab characters are displayed as vertical bar (|) characters.
As Jochen Arndt commented you could use owner drawing to implement your own drawing of the button text and so expand the tab characters in the text.
 
Share this answer
 
Seeing that all the answers you've received point you to make your own derived button class, I would say that it would be easier for you to see what's already done here in CP, you have a big button resource here: http://www.codeproject.com/KB/buttons/[^].

See the Owner draw area.

From there I've used Davide Calabro job: CButtonST v3.9 (MFC Flat buttons)[^] which can do what you need.

Learning how he have made it or using his code you'll get your desired result.

Good luck. :thumbsup:
 
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