using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; namespace DPumpHydr.WinFrmUI.WenSkin.Controls { public class WenButtonThreeLine : WenControl { public WenButtonThreeLine() : base() { this.Size = new Size(32, 32); this.BackColor = Color.Transparent; } #region 私有属性 private bool state = true; #endregion #region 公有属性 [DefaultValue(true), Category("Wen"), Description("开关状态")] public bool State { get => state; set { state = value; this.Invalidate(); } } [Category("Wen")] [Description("按钮样式颜色")] [RefreshProperties(RefreshProperties.Repaint)] [DefaultValue("Cyan")] public Color ButtonColor { get; set; } = Color.Gray; #endregion protected override void OnSizeChanged(EventArgs e) { base.OnSizeChanged(e); this.Size = new Size(32, 32); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; Brush brush = GetBrush(ButtonColor); Pen pen = new Pen(brush, 3); //画三横 g.DrawLine(pen, 1, 5 + 1, 30, 5 + 1); g.DrawLine(pen, 1, 15 + 1, 30, 15 + 1); g.DrawLine(pen, 1, 25 + 1, 30, 25 + 1); //画三个圆 if (State) { g.FillEllipse(brush, new Rectangle(1, 3, 6, 6)); g.FillEllipse(brush, new Rectangle(1, 13, 6, 6)); g.FillEllipse(brush, new Rectangle(1, 23, 6, 6)); } } protected override void OnMouseLeave(EventArgs e) { base.OnMouseLeave(e); this.BackColor = Color.Transparent; } protected override void OnMouseEnter(EventArgs e) { base.OnMouseEnter(e); this.BackColor = Color.FromArgb(63, 63, 65); } protected override void OnClick(EventArgs e) { if (State) State = false; else State = true; base.OnClick(e); } #region 颜色获取Brush private Brush GetBrush(string b) { return new SolidBrush(ColorTranslator.FromHtml(b)); } private Brush GetBrush(Color c) { return new SolidBrush(c); } #endregion } }