Vytvor si klasicky UserControl cez pridanie súboru a potom je to jednoduché, podedíš vlastnosti a udalosti :
public partial class TButton : UserControl
{
private bool ishover = false;
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
}
protected override void OnMouseMove(MouseEventArgs e)
{
if (!ishover)
{
ishover = true;
this.Invalidate();
}
base.OnMouseMove(e);
}
protected override void OnMouseLeave(EventArgs e)
{
if (ishover)
{
ishover = false;
this.Invalidate();
}
base.OnMouseLeave(e);
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
g.FillRectangle(new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), (ishover ? Color.Gray : Color.Silver), Color.WhiteSmoke, System.Drawing.Drawing2D.LinearGradientMode.Vertical), new Rectangle(0, 0, this.Width, this.Height));
SizeF TextSize = g.MeasureString(this.Text, this.Font);
g.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), this.Width / 2 - TextSize.Width / 2, this.Height / 2 - TextSize.Height / 2);
}
}
Aplikáciu spusti / prekompiluj a v design móde - v zozname komponent - Vlastné komponenty sa ti objaví TButton (ten prenesieš ako klasický button na plochu formulára a to je všetko).