
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);