tangxu
2024-11-04 ebd031e3bed6c1cfddce8fc9b98f7f9e95fb9e32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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
    }
 
 
}