Click here to Skip to main content
15,917,329 members
Articles / Programming Languages / C#

XButton Control for .NET

Rate me:
Please Sign up or sign in to vote.
1.87/5 (18 votes)
31 Mar 20041 min read 94K   434   31   8
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. Lots 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.

C#
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.


Written By
Pakistan Pakistan
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++

Comments and Discussions

 
GeneralUhh... Pin
Nathan Ridley1-Apr-04 11:53
Nathan Ridley1-Apr-04 11:53 
GeneralRe: Uhh... Pin
MicrosoftBob1-Apr-04 11:56
MicrosoftBob1-Apr-04 11:56 
Practicing up for a job on IBM's Lotus Notes team?
GeneralRe: Uhh... Pin
Nathan Ridley1-Apr-04 12:13
Nathan Ridley1-Apr-04 12:13 
GeneralRe: Uhh... Pin
Tomaž Štih1-Apr-04 18:51
Tomaž Štih1-Apr-04 18:51 
GeneralRe: Uhh... Pin
Tahir 1113-Apr-04 3:00
Tahir 1113-Apr-04 3:00 
GeneralRe: Uhh... Pin
Nathan Ridley3-Apr-04 13:13
Nathan Ridley3-Apr-04 13:13 
GeneralRe: Uhh... Pin
Arun Reginald Zaheeruddin3-May-04 18:15
Arun Reginald Zaheeruddin3-May-04 18:15 
GeneralRe: Uhh... Pin
Alan Zhao4-May-04 4:46
Alan Zhao4-May-04 4:46 

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

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