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
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
#region Imports
 
using System.Drawing;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region AirTabPage
 
    public class AirTabPage : TabControl
    {
        public AirTabPage()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
            DoubleBuffered = true;
            ItemSize = new(30, 115);
            SizeMode = TabSizeMode.Fixed;
            MouseMove += AirTabPage_MouseMove;
        }
 
        private void AirTabPage_MouseMove(object sender, MouseEventArgs e)
        {
            for (int i = 0; i < TabCount; i++)
            {
                // get their rectangle area and check if it contains the mouse cursor
                Rectangle r = GetTabRect(i);
                if (r.Contains(e.Location))
                {
                    // show the context menu here
                    System.Diagnostics.Debug.WriteLine("TabPressed: " + i);
                }
            }
        }
 
        protected override void CreateHandle()
        {
            base.CreateHandle();
            Alignment = TabAlignment.Left;
        }
 
        private Color C1 = Color.FromArgb(78, 87, 100);
        public Color SquareColor
        {
            get => C1;
            set
            {
                C1 = value;
                Invalidate();
            }
        }
 
        private Color _BaseColor = Color.White;
        public Color BaseColor
        {
            get => _BaseColor;
            set
            {
                _BaseColor = value;
                Invalidate();
            }
        }
 
        private Color _NormalTextColor = Color.DimGray;
        public Color NormalTextColor
        {
            get => _NormalTextColor;
            set
            {
                _NormalTextColor = value;
                Invalidate();
            }
        }
 
        private Color _SelectedTextColor = Color.Black;
        public Color SelectedTextColor
        {
            get => _SelectedTextColor;
            set
            {
                _SelectedTextColor = value;
                Invalidate();
            }
        }
 
        private Color _SelectedTabBackColor = Color.White;
        public Color SelectedTabBackColor
        {
            get => _SelectedTabBackColor;
            set
            {
                _SelectedTabBackColor = value;
                Invalidate();
            }
        }
 
        private Cursor _TabCursor = Cursors.Hand;
        public Cursor TabCursor
        {
            get => _TabCursor;
            set
            {
                _TabCursor = value;
                Invalidate();
            }
        }
 
        private bool OB = false;
        public bool ShowOuterBorders
        {
            get => OB;
            set
            {
                OB = value;
                Invalidate();
            }
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            Bitmap B = new(Width, Height);
            Graphics G = Graphics.FromImage(B);
 
            try
            {
                SelectedTab.BackColor = SelectedTabBackColor;
                SelectedTab.Cursor = Cursors.Default;
                Cursor = TabCursor;
            }
            catch
            {
            }
 
            G.Clear(BaseColor);
            G.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
 
            for (int i = 0; i <= TabCount - 1; i++)
            {
                Rectangle x2 = new(new Point(GetTabRect(i).Location.X - 2, GetTabRect(i).Location.Y - 2), new Size(GetTabRect(i).Width + 3, GetTabRect(i).Height - 1));
                Rectangle textrectangle = new(x2.Location.X + 20, x2.Location.Y, x2.Width - 20, x2.Height);
 
                if (i == SelectedIndex)
                {
                    G.FillRectangle(new SolidBrush(C1), new Rectangle(x2.Location, new Size(9, x2.Height)));
 
                    if (ImageList != null)
                    {
                        try
                        {
                            if (ImageList.Images[TabPages[i].ImageIndex] != null)
                            {
                                G.DrawImage(ImageList.Images[TabPages[i].ImageIndex], new Point(textrectangle.Location.X + 8, textrectangle.Location.Y + 6));
                                G.DrawString("      " + TabPages[i].Text, Font, new SolidBrush(SelectedTextColor), textrectangle, new StringFormat
                                {
                                    LineAlignment = StringAlignment.Center,
                                    Alignment = StringAlignment.Near
                                });
                            }
                            else
                            {
                                G.DrawString(TabPages[i].Text, Font, new SolidBrush(SelectedTextColor), textrectangle, new StringFormat
                                {
                                    LineAlignment = StringAlignment.Center,
                                    Alignment = StringAlignment.Near
                                });
                            }
                        }
                        catch
                        {
                            G.DrawString(TabPages[i].Text, Font, new SolidBrush(SelectedTextColor), textrectangle, new StringFormat
                            {
                                LineAlignment = StringAlignment.Center,
                                Alignment = StringAlignment.Near
                            });
                        }
                    }
                    else
                    {
                        G.DrawString(TabPages[i].Text, Font, new SolidBrush(SelectedTextColor), textrectangle, new StringFormat
                        {
                            LineAlignment = StringAlignment.Center,
                            Alignment = StringAlignment.Near
                        });
                    }
 
                }
                else
                {
                    if (ImageList != null)
                    {
                        try
                        {
                            if (ImageList.Images[TabPages[i].ImageIndex] != null)
                            {
                                G.DrawImage(ImageList.Images[TabPages[i].ImageIndex], new Point(textrectangle.Location.X + 8, textrectangle.Location.Y + 6));
                                G.DrawString("      " + TabPages[i].Text, Font, new SolidBrush(NormalTextColor), textrectangle, new StringFormat
                                {
                                    LineAlignment = StringAlignment.Center,
                                    Alignment = StringAlignment.Near
                                });
                            }
                            else
                            {
                                G.DrawString(TabPages[i].Text, Font, new SolidBrush(NormalTextColor), textrectangle, new StringFormat
                                {
                                    LineAlignment = StringAlignment.Center,
                                    Alignment = StringAlignment.Near
                                });
                            }
                        }
                        catch
                        {
                            G.DrawString(TabPages[i].Text, Font, new SolidBrush(NormalTextColor), textrectangle, new StringFormat
                            {
                                LineAlignment = StringAlignment.Center,
                                Alignment = StringAlignment.Near
                            });
                        }
                    }
                    else
                    {
                        G.DrawString(TabPages[i].Text, Font, new SolidBrush(NormalTextColor), textrectangle, new StringFormat
                        {
                            LineAlignment = StringAlignment.Center,
                            Alignment = StringAlignment.Near
                        });
                    }
                }
            }
 
            e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
            G.Dispose();
            B.Dispose();
        }
    }
 
    #endregion
}