111,098
社区成员




public class SkinCheckBox:CheckBox
{
private State state=State.Normal;
public SkinCheckBox()
{
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.BackColor = System.Drawing.Color.Transparent;
}
protected override void OnMouseEnter(EventArgs e)
{
state = State.MouseOver;
this.Invalidate();
base.OnMouseEnter(e);
}
protected override void OnMouseLeave(EventArgs e)
{
state = State.Normal;
this.Invalidate();
base.OnMouseLeave(e);
}
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
{
if ((e.Button & MouseButtons.Left) != MouseButtons.Left) return;
state = State.MouseDown;
this.Invalidate();
base.OnMouseDown(e);
}
protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
{
if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
state = State.Normal;
this.Invalidate();
base.OnMouseUp(e);
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
if (SkinImage.checkbox.img==null)
{
base.OnPaint(e);
return;
}
int i = (int)state;
if (!this.Enabled) i = 16;
if (this.CheckState == CheckState.Checked) i+=16;
if (this.CheckState == CheckState.Indeterminate) i+=16;
Rectangle rc = this.ClientRectangle;
Rectangle r1 = rc;;
Graphics g = e.Graphics;
base.OnPaint(e);
int cw = SystemInformation.MenuCheckSize.Width ;
if (this.CheckAlign == ContentAlignment.MiddleLeft)
{
r1=Rectangle.FromLTRB(0,(r1.Height-cw)/2,0+cw,(r1.Height+cw)/2);
}
else
{
r1=Rectangle.FromLTRB(r1.Right-cw-1,(r1.Height-cw)/2,r1.Right,(r1.Height+cw)/2);
}
SkinDraw.DrawRect1(g,SkinImage.checkbox,r1,i);
}
}