gradient fill in a Windows Form button

How to give my buttons a gradient background color?

Page 1 of 1

3 Replies - 16729 Views - Last Post: 17 May 2009 - 08:10 PM Rate Topic: -----

#1 plnelson  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 11-February 09

gradient fill in a Windows Form button

Posted 15 May 2009 - 07:53 PM

I want to give some buttons in a dialog box a gradient background color instead of a flat color. I tried overriding the Paint handler like I do for giving a dialog a gradient but this had the effect of overwriting the button text AND its 3D click behavior. (I just end up with a gradient-filled rectangle where the button was!)

When I Google for this I find that several people have written complete custom buttons that have gradient background colors but I can't find any examples of doing this with a regular Windows Form button. Can it be done, and, if so - how?

Thanks in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: gradient fill in a Windows Form button

#2 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: gradient fill in a Windows Form button

Posted 15 May 2009 - 08:50 PM

I would also stick with the idea of writing your own custom button. First of all it will be easier for you to customize it later. Second, it will require less effort.
Was This Post Helpful? 0
  • +
  • -

#3 plnelson  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 11-February 09

Re: gradient fill in a Windows Form button

Posted 16 May 2009 - 06:54 AM

View PostCore, on 15 May, 2009 - 07:50 PM, said:

I would also stick with the idea of writing your own custom button. First of all it will be easier for you to customize it later. Second, it will require less effort.


Could someone please elaborate on this? Why would changing the background fill on an existing Windows control be more work than writing a whole new control?

Changing the background fill on a dialog box from solid to gradient is easy - just a few lines of code in the Paint handler - why is/should changing the background fill on a button any harder?
Was This Post Helpful? 0
  • +
  • -

#4 bigtonyk  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 61
  • Joined: 17-May 09

Re: gradient fill in a Windows Form button

Posted 17 May 2009 - 08:10 PM

View Postplnelson, on 15 May, 2009 - 06:53 PM, said:

I want to give some buttons in a dialog box a gradient background color instead of a flat color. I tried overriding the Paint handler like I do for giving a dialog a gradient but this had the effect of overwriting the button text AND its 3D click behavior. (I just end up with a gradient-filled rectangle where the button was!)

When I Google for this I find that several people have written complete custom buttons that have gradient background colors but I can't find any examples of doing this with a regular Windows Form button. Can it be done, and, if so - how?

Thanks in advance!


Take a look at this MSDN article.

http://msdn.microsof...y/ms229655.aspx

It's a bit complex, but you can probably just copy and paste the code. Just ignore the part about using a Smart Device project.

Tony
Was This Post Helpful? 1

Page 1 of 1