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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#region Imports
 
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region TabPage
 
    public class TabPage : TabControl
    {
        private SmoothingMode _SmoothingType = SmoothingMode.HighQuality;
        public SmoothingMode SmoothingType
        {
            get => _SmoothingType;
            set
            {
                _SmoothingType = value;
                Invalidate();
            }
        }
 
        private CompositingQuality _CompositingQualityType = CompositingQuality.HighQuality;
        public CompositingQuality CompositingQualityType
        {
            get => _CompositingQualityType;
            set
            {
                _CompositingQualityType = value;
                Invalidate();
            }
        }
 
        private CompositingMode _CompositingType = CompositingMode.SourceOver;
        public CompositingMode CompositingType
        {
            get => _CompositingType;
            set
            {
                _CompositingType = value;
                Invalidate();
            }
        }
 
        private InterpolationMode _InterpolationType = InterpolationMode.HighQualityBicubic;
        public InterpolationMode InterpolationType
        {
            get => _InterpolationType;
            set
            {
                _InterpolationType = value;
                Invalidate();
            }
        }
 
        private PixelOffsetMode _PixelOffsetType = PixelOffsetMode.HighQuality;
        public PixelOffsetMode PixelOffsetType
        {
            get => _PixelOffsetType;
            set
            {
                _PixelOffsetType = value;
                Invalidate();
            }
        }
 
        private TextRenderingHint _TextRenderingType = TextRenderingHint.ClearTypeGridFit;
        public TextRenderingHint TextRenderingType
        {
            get => _TextRenderingType;
            set
            {
                _TextRenderingType = value;
                Invalidate();
            }
        }
 
        private StringAlignment _StringType = StringAlignment.Near;
        public StringAlignment StringType
        {
            get => _StringType;
            set
            {
                _StringType = value;
                Invalidate();
            }
        }
 
        private Color _FrameColor = Color.FromArgb(41, 50, 63);
        public Color FrameColor
        {
            get => _FrameColor;
            set
            {
                _FrameColor = value;
                Invalidate();
            }
        }
 
        private Color _PageColor = Color.FromArgb(50, 63, 74);
        public Color PageColor
        {
            get => _PageColor;
            set
            {
                _PageColor = value;
                Invalidate();
            }
        }
 
        private Color _ActiveForeColor = Color.FromArgb(254, 255, 255);
        public Color ActiveForeColor
        {
            get => _ActiveForeColor;
            set
            {
                _ActiveForeColor = value;
                Invalidate();
            }
        }
 
        private Color _NormalForeColor = Color.FromArgb(159, 162, 167);
        public Color NormalForeColor
        {
            get => _NormalForeColor;
            set
            {
                _NormalForeColor = value;
                Invalidate();
            }
        }
 
        private Color _ControlBackColor = Color.FromArgb(54, 57, 64);
        public Color ControlBackColor
        {
            get => _ControlBackColor;
            set
            {
                _ControlBackColor = value;
                Invalidate();
            }
        }
 
        private Color _LineColor = Color.FromArgb(25, 26, 28);
        public Color LineColor
        {
            get => _LineColor;
            set
            {
                _LineColor = value;
                Invalidate();
            }
        }
 
        private Color _ActiveTabColor = Color.FromArgb(35, 36, 38);
        public Color ActiveTabColor
        {
            get => _ActiveTabColor;
            set
            {
                _ActiveTabColor = value;
                Invalidate();
            }
        }
 
        private Color _TabColor = Color.FromArgb(54, 57, 64);
        public Color TabColor
        {
            get => _TabColor;
            set
            {
                _TabColor = value;
                Invalidate();
            }
        }
 
        private Color _ActiveLineTabColor = Color.FromArgb(89, 169, 222);
        public Color ActiveLineTabColor
        {
            get => _ActiveLineTabColor;
            set
            {
                _ActiveLineTabColor = value;
                Invalidate();
            }
        }
 
        private Color _LineTabColor = Color.FromArgb(54, 57, 64);
        public Color LineTabColor
        {
            get => _LineTabColor;
            set
            {
                _LineTabColor = value;
                Invalidate();
            }
        }
 
        public TabPage()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.DoubleBuffer, true);
 
            DoubleBuffered = true;
            ItemSize = new(44, 135);
            SizeMode = TabSizeMode.Fixed;
            DrawMode = TabDrawMode.OwnerDrawFixed;
        }
 
        protected override void CreateHandle()
        {
            base.CreateHandle();
 
            base.DoubleBuffered = true;
            SizeMode = TabSizeMode.Fixed;
            Alignment = TabAlignment.Left;
            Appearance = TabAppearance.Normal;
        }
 
        protected override void OnControlAdded(ControlEventArgs e)
        {
            base.OnControlAdded(e);
 
            if (e.Control is System.Windows.Forms.TabPage)
            {
                IEnumerator Enumerator;
                try
                {
                    Enumerator = Controls.GetEnumerator();
 
                    while (Enumerator.MoveNext())
                    {
                        System.Windows.Forms.TabPage Current = (System.Windows.Forms.TabPage)Enumerator.Current;
                        Current = new System.Windows.Forms.TabPage();
                    }
                }
                finally
                {
                    e.Control.BackColor = FrameColor;
                }
            }
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Bitmap B = new(Width, Height);
            Graphics G = Graphics.FromImage(B);
 
            Graphics _Graphics = G;
 
            _Graphics.Clear(FrameColor);
            _Graphics.SmoothingMode = SmoothingType;
            _Graphics.CompositingMode = CompositingType;
            _Graphics.PixelOffsetMode = PixelOffsetType;
            _Graphics.TextRenderingHint = TextRenderingType;
            _Graphics.CompositingQuality = CompositingQualityType;
 
            // Draw tab selector background
            _Graphics.FillRectangle(new SolidBrush(ControlBackColor), new Rectangle(-5, 0, ItemSize.Height + 4, Height));
            // Draw vertical line at the end of the tab selector rectangle
            _Graphics.DrawLine(new(LineColor), ItemSize.Height - 1, 0, ItemSize.Height - 1, Height);
 
            for (int TabIndex = 0; TabIndex <= TabCount - 1; TabIndex++)
            {
                if (TabPages[TabIndex].BackColor != PageColor)
                {
                    TabPages[TabIndex].BackColor = PageColor;
                }
 
                if (TabIndex == SelectedIndex)
                {
                    Rectangle TabRect = new(new Point(GetTabRect(TabIndex).Location.X - 2, GetTabRect(TabIndex).Location.Y - 2), new Size(GetTabRect(TabIndex).Width + 3, GetTabRect(TabIndex).Height - 8));
 
                    // Draw background of the selected tab
                    _Graphics.FillRectangle(new SolidBrush(ActiveTabColor), TabRect.X, TabRect.Y, TabRect.Width - 4, TabRect.Height + 3);
                    // Draw a tab highlighter on the background of the selected tab
                    Rectangle TabHighlighter = new(new Point(GetTabRect(TabIndex).X - 2, GetTabRect(TabIndex).Location.Y - (TabIndex == 0 ? 1 : 1)), new Size(4, GetTabRect(TabIndex).Height - 7));
                    _Graphics.FillRectangle(new SolidBrush(ActiveLineTabColor), TabHighlighter);
                    // Draw tab text
                    _Graphics.DrawString(TabPages[TabIndex].Text, new Font(Font.FontFamily, Font.Size, Font.Style), new SolidBrush(ActiveForeColor), new Rectangle(TabRect.Left + 40, TabRect.Top + 8, TabRect.Width - 40, TabRect.Height), new StringFormat { Alignment = StringType });
 
                    if (ImageList != null)
                    {
                        int Index = TabPages[TabIndex].ImageIndex;
 
                        if (!(Index == -1))
                        {
                            _Graphics.DrawImage(ImageList.Images[TabPages[TabIndex].ImageIndex], TabRect.X + 9, TabRect.Y + 6, 24, 24);
                        }
                    }
                }
                else
                {
                    Rectangle TabRect = new(new Point(GetTabRect(TabIndex).Location.X - 2, GetTabRect(TabIndex).Location.Y - 2), new Size(GetTabRect(TabIndex).Width + 3, GetTabRect(TabIndex).Height - 8));
 
                    // Draw background of the tab
                    _Graphics.FillRectangle(new SolidBrush(TabColor), TabRect.X, TabRect.Y, TabRect.Width - 4, TabRect.Height + 3);
                    // Draw a tab highlighter on the background of the tab
                    Rectangle TabHighlighter = new(new Point(GetTabRect(TabIndex).X - 2, GetTabRect(TabIndex).Location.Y - (TabIndex == 0 ? 1 : 1)), new Size(4, GetTabRect(TabIndex).Height - 7));
                    _Graphics.FillRectangle(new SolidBrush(LineTabColor), TabHighlighter);
 
                    _Graphics.DrawString(TabPages[TabIndex].Text, new Font(Font.FontFamily, Font.Size, Font.Style), new SolidBrush(NormalForeColor), new Rectangle(TabRect.Left + 40, TabRect.Top + 8, TabRect.Width - 40, TabRect.Height), new StringFormat { Alignment = StringType });
 
                    if (ImageList != null)
                    {
                        int Index = TabPages[TabIndex].ImageIndex;
 
                        if (!(Index == -1))
                        {
                            _Graphics.DrawImage(ImageList.Images[TabPages[TabIndex].ImageIndex], TabRect.X + 9, TabRect.Y + 6, 24, 24);
                        }
                    }
 
                }
            }
 
            e.Graphics.SmoothingMode = SmoothingType;
            e.Graphics.CompositingMode = CompositingType;
            e.Graphics.PixelOffsetMode = PixelOffsetType;
            e.Graphics.TextRenderingHint = TextRenderingType;
            e.Graphics.InterpolationMode = InterpolationType;
            e.Graphics.CompositingQuality = CompositingQualityType;
 
            e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
            G.Dispose();
            B.Dispose();
        }
    }
 
    #endregion
}