Introduction
In this sample is shown how to build a simple button with a nice graphic interface. My control would be an example about using the drawings classes and the essentials key-words. I decide to draw an unusual button like this picture below:

First step
First of all I declare my new class : public class SpringButton : Control {}
How to expose proprieties
After that I expose some essential proprieties like the size in pixel of the triangles and the second color of the button. All the others proprieties that I need are yet behind the System.Windows.Form.Control class.
//this variable say if the
//mouse is over the control
private bool Sel = false;
private Color BackColor2= Color.Gray;
public Color BackColorEnd
{
get
{
return BackColor2;
}
set
{
BackColor2=value;
this.Invalidate();
}
}
int _triangle =25;
//I add a property
//that's the length of
//a triangle rectangle (45°)
public int Triangle
{
get
{
return _triangle;
}
set
{
_triangle=value;
//if length change I update
//the control
this.Invalidate(true);
}
}
Mouse "lighting"Another important step is to set the control as "selected" when the mouse is over. So if the mouse is over the control the back color and the border color are inverted. (See the code in the OnPaint override)
//set the button as "selected" on mouse entering
//and as not selected on mouse leaving
protected override void OnMouseEnter(EventArgs e)
{
eberirigoyenPosted Apr 5, 2006, 7:29 PM
why do you have logic to define the colors in the paint event? shouldn't you just be using all the variables that should already be set to just paint?