using System;
using System.Drawing;
using System.Windows.Forms;
namespace CustomTools.GUI
{
public class MyToolbarButton : System.Windows.Forms.PictureBox
{
private bool Over = false;
private bool selected = false;
public MyToolbarButton()
{
//
// TODO: Add constructor logic here
//
SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint |
ControlStyles.DoubleBuffer,
true);
this.Size = new Size(22,22);
}
/// <summary>Specify if this button is currently pressed/toggled</summary>
public bool Selected
{
set
{
selected = value;
this.Invalidate();
}
get
{
return selected;
}
}
protected override void OnMouseHover(EventArgs e)
{
this.Over = true;
this.Invalidate();
}
protected override void OnMouseLeave(EventArgs e)
{
this.Over = false;
this.Invalidate();
}
private void InitializeComponent()
{
this.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaint (e);
if (Over)
{
e.Graphics.DrawRectangle(Pens.DarkGray, 0,0,this.Width - 1, this.Height - 1);
}
if (selected)
{
e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(85, Color.SteelBlue)),
(this.Width - this.Image.Width) / 2, (this.Height - this.Image.Height) / 2,
this.Image.Width,this.Image.Height);
}
}
}
}