Click here to Skip to main content
Licence 
First Posted 31 Mar 2004
Views 81,570
Bookmarked 29 times

XButton control for .NET

By | 31 Mar 2004 | Article
Developing a gradient button in C#

Introduction

I have been a great fan of writing custom controls. Earlier, I have done this custom control stuff in ATL and MFC but to be very frank C# is very exciting. Lot’s of things are already provided for which we have to do a lot of coding in C++.

Using the code

You can change the button gradient using the start color and end color properties. Other properties are selected text color i.e. the color in which text is drawn when the mouse is down, and animated gradient style.

One of the exciting things is the direction of animated gradient. They are seen when you hover the mouse on the button. You can set it with AnimatedGradient property

Gradient Starts Animation

When you click the mouse button you will see that the text is bold which is enclosed within the black rectangle producing the effect of mouse click.

Points of interest

I didn’t support opacity in XButton control. Be careful with gradient opacity because if you decrease it, then you will see the original button text producing duplicate text with one that you write with DrawSring for the default text.

The other important thing is the clumsy digit 12. Because the font height is 12 therefore subtract it from the ordinate of center point so that your text appears within the center of button.

dc.DrawString (this.Text, new Font ("Times New Roman", 12, FontStyle.Bold), 
  clkedbrushtxt, centerPoint.X, centerPoint.Y -12, sf); 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Tahir Ali Mirza



Pakistan Pakistan

Member

I have masters degree in Computer Science from University of Karahi.I have been programming in C++,MFC,ATL,C#,VB.NET and ASP.NET.
My favorite hobby is finding the fastest way of accessing database from C++

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralUhh... PinmemberNathan Ridley11:53 1 Apr '04  
GeneralRe: Uhh... PinmemberMicrosoftBob11:56 1 Apr '04  
GeneralRe: Uhh... PinmemberNathan Ridley12:13 1 Apr '04  
GeneralRe: Uhh... PinmemberTomaž Štih18:51 1 Apr '04  
GeneralRe: Uhh... PinmemberMirza Tahir Ali3:00 3 Apr '04  
GeneralRe: Uhh... PinmemberNathan Ridley13:13 3 Apr '04  
GeneralRe: Uhh... PinmemberAaron Reginald18:15 3 May '04  
GeneralRe: Uhh... PinmemberAlan Zhao4:46 4 May '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 1 Apr 2004
Article Copyright 2004 by Tahir Ali Mirza
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid