Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to change color of button in vc++ mfc for vs2008

Sorry Its not working please give details please
Your code is not working please give me details please please,Its urget
Posted
Updated 1-Mar-17 1:13am
v3
Comments
Maximilien 31-Jan-13 9:26am    
What have you tried so far ? what did your google searches returned ?

It is also needed to include the header afxbutton.h, i.e. #include "afxbutton.h"
 
Share this answer
 
Use that

C++
m_Button1.m_nFlatStyle = CMFCButton::BUTTONSTYLE_NOBORDERS;


it will remove all default windows tag.

So Final solution is

	m_Button1.m_nFlatStyle = CMFCButton::BUTTONSTYLE_NOBORDERS;//required for flatering and use bg color
m_Button1.m_bTransparent = false;//reg for use bg color
m_Button1.SetFaceColor( RGB(211, 84, 0), true);
 
Share this answer
 
Comments
Richard MacCutchan 22-Feb-17 7:41am    
FOUR years too late.
Chris Maunder 15-Oct-21 9:47am    
Not sure why this is a problem, Richard. People still Google for this problem and this seems to be a solid answer that included the tip on setting transparency to false that the other answer didn't include. (and yes, my comment is also 4 years too late! :))
Richard MacCutchan 15-Oct-21 9:50am    
Well I wrote that comment more than four years ago. And these days I have difficulty remembering what I wrote last week.
Michael Haephrati 15-Oct-21 7:05am    
Great answer! That worked. Got my 5 stars.
1. Place Button with Resource Editor
2. Add Variable for Button (for example m_StopButton ) with Wizard
3. Rename
C++
CButton  m_StopButtonto;

to
C++
CMFCButton  m_StopButton;

4. Change some visible features

C++
// Set the background color for the button text.
  m_StopButton.SetFaceColor(RGB(255,0,0),true);
  m_StopButton.SetTextColor(RGB(0,0,255));
  // Set the tooltip of the button.
  m_StopButton.SetTooltip(_T("This is my Stop Button!"));
 
Share this answer
 
v3
Comments
Gbenbam 3-Aug-15 10:33am    
I used this code on VS2010 but id did not seem to work.

I added an MFC button from the resource editor and wrote.

CMFCButton *pButton = (CMFCButton *)GetDlgItem(IDC_MFCBUTTON1);
pButton->StFaceColor(RGB(255,0,0),true);
pButton->SetTextColor(RGB(0,0,255));

I wonder why the code doesn't seem to work.


merano 3-Aug-15 13:35pm    
(1)Note that the background is not filled when the CMFCButton::m_bTransparent member variable is TRUE.
https://msdn.microsoft.com/de-de/library/Bb983413.aspx


(2)SetFaceColor() is ignored by modern theme engines. The wizard greates something like:

CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));

You can comment this line out to disable custom MFC themes. This works, but the button
will not look good because of classic theme.

Possibly you can Load a Color-Bitmap to get the color you want.

Another solution would be to do an ownerdraw button - handling the OnDrawItem() or WM_DRAWITEM
message and do the painting yourself.
Michael Haephrati 15-Oct-21 7:03am    
This solution doesn't seem to work

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