public class BzToggleButton : CheckBox { private Color onBackColor =
Color.MediumSlateBlue; private Color onToggleColor = Color.WhiteSmoke; private
Color offBackColor = Color.Gray; private Color offToggleColor =
Color.Gainsboro; private bool solidStyle = true; [Category("BZ Advance")]
public Color OnBackColor { get { return onBackColor; } set { onBackColor =
value; this.Invalidate(); } } [Category("BZ Advance")] public Color
OnToggleColor { get { return onToggleColor; } set { onToggleColor = value;
this.Invalidate(); } } [Category("BZ Advance")] public Color OffBackColor { get
{ return offBackColor; } set { offBackColor = value; this.Invalidate(); } }
[Category("BZ Advance")] public Color OffToggleColor { get { return
offToggleColor; } set { offToggleColor = value; this.Invalidate(); } } public
override string Text { get { return base.Text; } set { } } [Category("BZ
Advance")] public bool SolidStyle { get { return solidStyle; } set { solidStyle
= value; this.Invalidate(); } } public BzToggleButton() { this.MinimumSize =
new Size(45, 22); } private GraphicsPath GetFigurePath() { int arcSize =
this.Height - 1; Rectangle leftArc = new Rectangle(0, 0, arcSize, arcSize);
Rectangle rightArc = new Rectangle(this.Width-arcSize-2,0, arcSize, arcSize);
GraphicsPath path = new GraphicsPath(); path.StartFigure();
path.AddArc(leftArc, 90, 180); path.AddArc(rightArc, 270, 180);
path.CloseAllFigures(); return path; } protected override void
OnPaint(PaintEventArgs pevent) { int toggleSize = this.Height - 5; Graphics
graphics = pevent.Graphics; graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.Clear(this.Parent.BackColor); if (this.Checked) { if (solidStyle) {
graphics.FillPath(new SolidBrush(onBackColor), GetFigurePath()); } else {
graphics.DrawPath(new Pen(OnBackColor, 2), GetFigurePath()); }
graphics.FillEllipse(new SolidBrush(onToggleColor), new Rectangle(this.Width -
this.Height + 1 ,2, toggleSize, toggleSize)); } else { if (solidStyle) {
graphics.FillPath(new SolidBrush(offBackColor), GetFigurePath()); } else {
graphics.DrawPath(new Pen(offBackColor, 2), GetFigurePath()); }
graphics.FillEllipse(new SolidBrush(offToggleColor), new Rectangle(2 , 2,
toggleSize, toggleSize )); } } }
 

技术
今日推荐
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:766591547
关注微信