Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello,

How can fill gradient to a button in MFC C++.

My application is MFC Application in VS 2003 .net and i am using SDI Application which means there are so many FormView which i am displaying in a single window.

Can anyone give me a suggestion in creating gradient button?
Posted

Look at this. There are a lot of different buttons there.
 
Share this answer
 
You could set the style BS_OWNERDRAW
to constitute it by you own gusto... :)
 
Share this answer
 
Hi Eugen,

My owner draw is true. i have tried but i am not able to create gradient button.

Actually i am using these button in my own created dialogbar whose background is colored. Now my buttons are transparent mode so background of dialogbar is background of button. when i am clicking on button, background of buttons changed to White.

How to get rid of this?
 
Share this answer
 
1. Please derivate you own button class:
class CYourButton : public CButton
{
public:
  CYourButton();
  virtual ~CYourButton();

  // Overridables (for owner draw only)
  virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
}

...and implement your own drawing (to be not transparent).

2. Have your bar (of the button)
the DoDataExchange(CDataExchange* pDX) function ?
 
Share this answer
 
Yes Eugen, My Dialogbar having DoDataExchange function.

Eugen, I am not that much expert of creating my own colored button using DrawItem.

Do you have any link for this, please do send it to me.
 
Share this answer
 
Very nice :)

3. Please place a variable of the type CYourButton -
in to your bar class:
{
  CYourButton m_cYourButton;
...
}

...and modify its exchange function:
void CYourBar::DoDataExchange(CDataExchange* pDX)
{
  CBaseOfYourBar::DoDataExchange(pDX);
  // second parameter is button ID from your .rc file
  DDX_Control(pDX, IDC_BUTTON1, m_cYourButton);
...
}


4. Constitute your drawing procedure
http://msdn.microsoft.com/en-us/library/y0k9f0a4(VS.80).aspx[^]

5. You can fill gradient surface with the lines
or use other complete methods (must be searched) :)
 
Share this answer
 
v2
Eugen, I have done according to you. I have also created DrawItem. but control is not coming to "DrawItem" of CyourButton.

Can you tell how can i achieve this?
 
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