Скрытый текст
using System;
using System.Drawing;
using System.Windows.Forms;
public class MCheckBox : Control
{
private bool _checked;
private Color C1 = Color.FromArgb(0x1f, 0x1f, 0x1f);
private Color C2 = Color.FromArgb(0x29, 0x29, 0x29);
private Color C3 = Color.FromArgb(0x33, 0x33, 0x33);
private Color C4 = Color.FromArgb(0, 0, 0, 0);
private Color C5 = Color.FromArgb(0x19, 0xff, 0xff, 0xff);
private int State;
public MCheckBox()
{
this.ForeColor = Color.FromArgb(50, 210, 50);
}
protected override void OnClick(EventArgs e)
{
this._checked = !this._checked;
}
protected override void OnMouseDown(MouseEventArgs e)
{
this.State = 2;
base.Invalidate();
base.OnMouseDown(e);
}
protected override void OnMouseEnter(EventArgs e)
{
this.State = 1;
base.Invalidate();
base.OnMouseEnter(e);
}
protected override void OnMouseLeave(EventArgs e)
{
this.State = 0;
base.Invalidate();
base.OnMouseLeave(e);
}
protected override void OnMouseUp(MouseEventArgs e)
{
this.State = 1;
base.Invalidate();
base.OnMouseUp(e);
}
protected override void OnPaint(PaintEventArgs e)
{
using (Bitmap bitmap = new Bitmap(base.Width, base.Height))
{
using (Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.Clear(Color.FromArgb(0x29, 0x29, 0x29));
int num = 15;
int height = 14;
if ((this.State == 1) && this._checked)
{
graphics.DrawRectangle(new Pen(this.C2), 1, 1, num - 3, height);
Draw.Gradient(graphics, Color.FromArgb(0, 120, 0), Color.FromArgb(0, 110, 0), 1, 1, num - 2, height);
graphics.DrawRectangle(new Pen(this.C1), 0, 0, num - 1, height);
}
else if ((this.State == 2) && this._checked)
{
graphics.DrawRectangle(new Pen(this.C2), 1, 1, num - 3, height - 3);
Draw.Gradient(graphics, Color.FromArgb(0, 100, 0), Color.FromArgb(0, 90, 0), 1, 1, num - 2, height);
graphics.DrawRectangle(new Pen(this.C1), 0, 0, num - 1, height);
}
else if ((this.State == 1) && !this._checked)
{
graphics.DrawRectangle(new Pen(this.C2), 1, 1, num - 3, height - 3);
Draw.Gradient(graphics, Color.FromArgb(120, 0, 0), Color.FromArgb(110, 0, 0), 1, 1, num - 2, height);
graphics.DrawRectangle(new Pen(this.C1), 0, 0, num - 1, height);
}
else if ((this.State == 2) && !this._checked)
{
graphics.DrawRectangle(new Pen(this.C2), 1, 1, num - 3, height - 3);
Draw.Gradient(graphics, Color.FromArgb(100, 0, 0), Color.FromArgb(90, 0, 0), 1, 1, num - 2, height);
graphics.DrawRectangle(new Pen(this.C1), 0, 0, num - 1, height);
}
else if (this._checked)
{
graphics.DrawRectangle(new Pen(this.C2), 1, 1, num - 3, height - 3);
Draw.Gradient(graphics, Color.FromArgb(0, 110, 0), Color.FromArgb(0, 100, 0), 1, 1, num - 2, height);
graphics.DrawRectangle(new Pen(this.C1), 0, 0, num - 1, height);
}
else if (!this._checked)
{
graphics.DrawRectangle(new Pen(this.C2), 1, 1, num - 3, height - 3);
Draw.Gradient(graphics, Color.FromArgb(110, 0, 0), Color.FromArgb(100, 0, 0), 1, 1, num - 2, height);
graphics.DrawRectangle(new Pen(this.C1), 0, 0, num - 1, height);
}
graphics.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), (float) 16f, (float) 1f);
e.Graphics.DrawImage((Image) bitmap.Clone(), 0, 0);
}
}
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
}
public bool Checked
{
get
{
return this._checked;
}
set
{
this._checked = value;
base.Invalidate();
}
}
}
Скрытый текст
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
public class Draw
{
public static void Blend(Graphics g, Color c1, Color c2, Color c3, float c, int d, int x, int y, int width, int height)
{
ColorBlend blend = new ColorBlend(3);
blend.Colors = new Color[] { c1, c2, c3 };
float[] numArray = new float[3];
numArray[1] = c;
numArray[2] = 1f;
blend.Positions = numArray;
Rectangle rect = new Rectangle(x, y, width, height);
using (LinearGradientBrush brush = new LinearGradientBrush(rect, c1, c1, (LinearGradientMode) d))
{
brush.InterpolationColors = blend;
g.FillRectangle(brush, rect);
}
}
public static void Gradient(Graphics g, Color c1, Color c2, int x, int y, int width, int height)
{
Rectangle rect = new Rectangle(x, y, width, height);
using (LinearGradientBrush brush = new LinearGradientBrush(rect, c1, c2, LinearGradientMode.Vertical))
{
g.FillRectangle(brush, rect);
}
}
}