yangyin
2025-03-27 b0de14c2670b9ff0079dacfb4b7457b438368f11
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Colors;
using DPumpHydr.WinFrmUI.RLT.Util;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region HopeTabPage
 
    public class HopeTabPage : TabControl
    {
        #region Variables
        private int enterIndex;
        private bool enterFlag = false;
        private Color _baseColor = Color.FromArgb(44, 55, 66);
        private Color _themeColorA = HopeColors.PrimaryColor;
        private Color _themeColorB = Color.FromArgb(150, HopeColors.PrimaryColor);
        private Color _foreColorA = Color.Silver;
        private Color _foreColorB = Color.Gray;
        private Color _foreColorC = Color.FromArgb(150, Color.White);
 
        private TextState _TitleTextState = TextState.Normal;
        private SmoothingMode _SmoothingType = SmoothingMode.HighQuality;
        private PixelOffsetMode _PixelOffsetType = PixelOffsetMode.HighQuality;
        private TextRenderingHint _TextRenderingType = TextRenderingHint.ClearTypeGridFit;
        #endregion
 
        #region Settings
        public SmoothingMode SmoothingType
        {
            get => _SmoothingType;
            set
            {
                _SmoothingType = value;
                Invalidate();
            }
        }
 
        public PixelOffsetMode PixelOffsetType
        {
            get => _PixelOffsetType;
            set
            {
                _PixelOffsetType = value;
                Invalidate();
            }
        }
 
        public TextRenderingHint TextRenderingType
        {
            get => _TextRenderingType;
            set
            {
                _TextRenderingType = value;
                Invalidate();
            }
        }
 
        public Color BaseColor
        {
            get => _baseColor;
            set
            {
                _baseColor = value;
                Invalidate();
            }
        }
 
        public Color ThemeColorA
        {
            get => _themeColorA;
            set
            {
                _themeColorA = value;
                Invalidate();
            }
        }
 
        public Color ThemeColorB
        {
            get => _themeColorB;
            set
            {
                _themeColorB = value;
                Invalidate();
            }
        }
 
        public Color ForeColorA
        {
            get => _foreColorA;
            set
            {
                _foreColorA = value;
                Invalidate();
            }
        }
 
        public Color ForeColorB
        {
            get => _foreColorB;
            set
            {
                _foreColorB = value;
                Invalidate();
            }
        }
 
        public Color ForeColorC
        {
            get => _foreColorC;
            set
            {
                _foreColorC = value;
                Invalidate();
            }
        }
 
        public enum TextState
        {
            Upper,
            Lower,
            Normal
        }
 
        public TextState TitleTextState
        {
            get => _TitleTextState;
            set
            {
                _TitleTextState = value;
                Invalidate();
            }
        }
 
        #endregion
 
        #region Functions
        private string TitleText(string Text)
        {
            return TitleTextState switch
            {
                TextState.Upper => Text.ToUpperInvariant(),
                TextState.Lower => Text.ToLowerInvariant(),
                _ => Text,
            };
        }
        #endregion
 
        public override Rectangle DisplayRectangle
        {
            get
            {
                Rectangle rect = base.DisplayRectangle;
                return new Rectangle(rect.Left - 4, rect.Top - 4, rect.Width + 8, rect.Height + 8);
            }
        }
 
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x02000000;
                return cp;
            }
        }
 
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
 
            enterFlag = true;
 
            for (int i = 0; i < TabCount; i++)
            {
                Rectangle tempRect = GetTabRect(i);
                if (tempRect.Contains(e.Location))
                {
                    enterIndex = i;
                }
            }
 
            Invalidate();
        }
 
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);
            enterFlag = false;
            Invalidate();
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics graphics = e.Graphics;
            graphics.SmoothingMode = SmoothingType;
            graphics.PixelOffsetMode = PixelOffsetType;
            graphics.TextRenderingHint = TextRenderingType;
            graphics.Clear(_baseColor);
 
            for (int i = 0; i < TabCount; i++)
            {
                if (i == SelectedIndex)
                {
                    graphics.FillRectangle(new SolidBrush(_themeColorA), GetTabRect(i).X + 3, ItemSize.Height - 3, ItemSize.Width - 6, 3);
                    graphics.DrawString(TitleText(TabPages[i].Text), Font, new SolidBrush(_foreColorA), GetTabRect(i), HopeStringAlign.Center);
                }
                else
                {
                    if (i == enterIndex && enterFlag)
                    {
                        graphics.FillRectangle(new SolidBrush(_themeColorB), GetTabRect(i).X + 3, ItemSize.Height - 3, ItemSize.Width - 6, 3);
                        graphics.DrawString(TitleText(TabPages[i].Text), Font, new SolidBrush(_foreColorC), GetTabRect(i), HopeStringAlign.Center);
                    }
                    else
                    {
                        graphics.DrawString(TitleText(TabPages[i].Text), Font, new SolidBrush(_foreColorB), GetTabRect(i), HopeStringAlign.Center);
                    }
                }
            }
        }
 
        public HopeTabPage()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer, true);
            DoubleBuffered = true;
            Font = new("Segoe UI", 12F);
            SizeMode = TabSizeMode.Fixed;
            ItemSize = new(120, 40);
        }
    }
 
    #endregion
}