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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
 
namespace DPumpHydr.WinFrmUI.WenSkin.Controls
{
    public class WenButtonTriangle : WenControl
    {
 
 
        public WenButtonTriangle() : base()
        {
            this.Size = new Size(32, 32);
            this.BackColor = Color.Transparent;
        }
 
        #region 私有属性
 
        private WenButtonTriangleStyle closeStyle = WenButtonTriangleStyle.Right;
        private WenButtonTriangleStyle openStyle = WenButtonTriangleStyle.Bottom;
        private bool state;
 
        #endregion
 
 
        #region 公有属性
 
        [DefaultValue(WenButtonTriangleStyle.Right), Category("Wen"), Description("关闭样式箭头方向")]
        public WenButtonTriangleStyle CloseStyle { get => closeStyle; set => closeStyle = value; }
        [DefaultValue(WenButtonTriangleStyle.Bottom), Category("Wen"), Description("打开样式箭头方向")]
        public WenButtonTriangleStyle OpenStyle { get => openStyle; set => openStyle = value; }
 
        [DefaultValue(false), Category("Wen"), Description("开关状态")]
        public bool State { get => state; set { state = value; this.Invalidate(); } }
 
        [Category("Wen")]
        [Description("按钮样式颜色")]
        [RefreshProperties(RefreshProperties.Repaint)]
        [DefaultValue(typeof(Color), "199,199,199")]
        public Color ButtonColor { get; set; } = Color.FromArgb(199, 199, 199);
 
        #endregion
 
        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);
            this.Height = this.Width;
        }
        protected override void OnClick(EventArgs e)
        {
            if (State)
                State = false;
            else
                State = true;
            base.OnClick(e);
        }
 
        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 WenOnPaint(Graphics g, Rectangle rec, PaintEventArgs e)
        {
            base.WenOnPaint(g, rec, e);
 
            if (State)
            {
                FillTriangle(OpenStyle, g, rec);
            }
            else
            {
                FillTriangle(CloseStyle, g, rec);
            }
        }
 
        private void FillTriangle(WenButtonTriangleStyle style, Graphics g, Rectangle rec)
        {
            rec = new Rectangle(rec.X, rec.Y, rec.Width - 1, rec.Height - 1);
            if (style == WenButtonTriangleStyle.Left)
                FillTriangleLeft(g, rec);
            if (style == WenButtonTriangleStyle.Right)
                FillTriangleRitht(g, rec);
            if (style == WenButtonTriangleStyle.Top)
                FillTriangTop(g, rec);
            if (style == WenButtonTriangleStyle.Bottom)
                FillTriangBottom(g, rec);
        }
 
 
        private void FillTriangleRitht(Graphics g, Rectangle rec)
        {
            Point point1 = new Point(rec.X, rec.Y);
            Point point2 = new Point(rec.X + rec.Width, rec.Y + rec.Height / 2);
            Point point3 = new Point(rec.X, rec.Y + rec.Height);
            GdiTriangLine(g, point1, point2, point3);
        }
        private void FillTriangleLeft(Graphics g, Rectangle rec)
        {
            Point point1 = new Point(rec.X + rec.Width, rec.Y);
            Point point2 = new Point(rec.X, rec.Y + rec.Height / 2);
            Point point3 = new Point(rec.X + rec.Width, rec.Y + rec.Height);
            GdiTriangLine(g, point1, point2, point3);
        }
        private void FillTriangBottom(Graphics g, Rectangle rec)
        {
            Point point1 = new Point(rec.X, rec.Y);
            Point point2 = new Point(rec.X + rec.Width / 2, rec.Y + rec.Y + rec.Height);
            Point point3 = new Point(rec.X + rec.Width, rec.Y);
            GdiTriangLine(g, point1, point2, point3);
        }
        private void FillTriangTop(Graphics g, Rectangle rec)
        {
            Point point1 = new Point(rec.X, rec.Y + rec.Height);
            Point point2 = new Point(rec.X + rec.Width / 2, rec.Y);
            Point point3 = new Point(rec.X + rec.Width, rec.Y + rec.Height);
            //Point[] pntArr = { point1, point2, point3 };
            //g.FillPolygon(GetBrush(ButtonColor), pntArr);
            GdiTriangLine(g, point1, point2, point3);
        }
 
        //三点画线条
        private void GdiTriangLine(Graphics g, Point point1, Point point2, Point point3)
        {
            using Pen pen = new Pen(new SolidBrush(ButtonColor), 1.6f);
            g.DrawLine(pen, point1, point2);
            g.DrawLine(pen, point2, point3);
        }
    }
 
    //三角形按钮方向
    public enum WenButtonTriangleStyle
    {
        Left = 1,
        Right = 2,
        Top = 3,
        Bottom = 4,
    }
}