![](/KB/buttons/MirzaXButton/image002.jpg)
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
![](/KB/buttons/MirzaXButton/image004.jpg)
![](/KB/buttons/MirzaXButton/image006.jpg)
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.
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++