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
#region Imports
 
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region SkyComboBox
 
    public class SkyComboBox : ComboBox
    {
        #region " Control Help - Properties & Flicker Control "
 
        private int _StartIndex = 0;
        public int StartIndex
        {
            get => _StartIndex;
            set
            {
                _StartIndex = value;
                try
                {
                    base.SelectedIndex = value;
                }
                catch
                {
                }
                Invalidate();
            }
        }
 
        public void ReplaceItem(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();
            try
            {
                if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                {
                    e.Graphics.FillRectangle(new SolidBrush(_highlightColor), e.Bounds);
                    LinearGradientBrush gloss = new(e.Bounds, ListSelectedBackColorA, ListSelectedBackColorB, 90);
                    e.Graphics.FillRectangle(gloss, new Rectangle(new Point(e.Bounds.X, e.Bounds.Y), new Size(e.Bounds.Width, e.Bounds.Height)));
                    e.Graphics.DrawRectangle(new(ListBorderColor) { DashStyle = ListDashType }, new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height - 1));
                }
                else
                {
                    e.Graphics.FillRectangle(new SolidBrush(ListBackColor), e.Bounds);
                }
 
                using SolidBrush b = new(ListForeColor);
                e.Graphics.DrawString(base.GetItemText(base.Items[e.Index]), e.Font, b, new Rectangle(e.Bounds.X + 2, e.Bounds.Y, e.Bounds.Width - 4, e.Bounds.Height));
            }
            catch
            {
            }
            e.DrawFocusRectangle();
        }
 
        protected void DrawTriangle(Color Clr, Point FirstPoint, Point SecondPoint, Point ThirdPoint, Graphics G)
        {
            List<Point> points = new()
            {
                FirstPoint,
                SecondPoint,
                ThirdPoint
            };
            G.FillPolygon(new SolidBrush(Clr), points.ToArray());
        }
 
        private Color _highlightColor = Color.FromArgb(121, 176, 214);
        public Color ItemHighlightColor
        {
            get => _highlightColor;
            set
            {
                _highlightColor = value;
                Invalidate();
            }
        }
        #endregion
 
        #region Variables
        private SmoothingMode _SmoothingType = SmoothingMode.HighQuality;
        #endregion
 
        #region Settings
        public SmoothingMode SmoothingType
        {
            get => _SmoothingType;
            set
            {
                _SmoothingType = value;
                Invalidate();
            }
        }
 
        public Color BGColorA { get; set; } = Color.FromArgb(245, 245, 245);
 
        public Color BGColorB { get; set; } = Color.FromArgb(230, 230, 230);
 
        public Color BorderColorA { get; set; } = Color.FromArgb(252, 252, 252);
 
        public Color BorderColorB { get; set; } = Color.FromArgb(249, 249, 249);
 
        public Color BorderColorC { get; set; } = Color.FromArgb(189, 189, 189);
 
        public Color BorderColorD { get; set; } = Color.FromArgb(200, 168, 168, 168);
 
        public Color TriangleColorA { get; set; } = Color.FromArgb(121, 176, 214);
 
        public Color TriangleColorB { get; set; } = Color.FromArgb(27, 94, 137);
 
        public Color LineColorA { get; set; } = Color.White;
 
        public Color LineColorB { get; set; } = Color.FromArgb(189, 189, 189);
 
        public Color LineColorC { get; set; } = Color.White;
 
        public Color ListForeColor { get; set; } = Color.Black;
 
        public Color ListBackColor { get; set; } = Color.FromArgb(255, 255, 255, 255);
 
        public Color ListBorderColor { get; set; } = Color.FromArgb(50, Color.Black);
 
        public DashStyle ListDashType { get; set; } = DashStyle.Dot;
 
        public Color ListSelectedBackColorA { get; set; } = Color.FromArgb(15, Color.White);
 
        public Color ListSelectedBackColorB { get; set; } = Color.FromArgb(0, Color.White);
        #endregion
 
        public SkyComboBox() : base()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.DoubleBuffer | ControlStyles.SupportsTransparentBackColor, true);
            DrawMode = DrawMode.OwnerDrawFixed;
            BackColor = Color.Transparent;
            ForeColor = Color.FromArgb(27, 94, 137);
            Font = new("Verdana", 6.75f, FontStyle.Bold);
            DropDownStyle = ComboBoxStyle.DropDownList;
            DoubleBuffered = true;
            Size = new(75, 21);
            ItemHeight = 16;
            DrawItem += new DrawItemEventHandler(ReplaceItem);
            Cursor = Cursors.Hand;
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            Bitmap B = new(Width, Height);
            Graphics G = Graphics.FromImage(B);
            G.SmoothingMode = SmoothingType;
 
            G.Clear(BackColor);
            LinearGradientBrush bodyGradNone = new(new Rectangle(0, 0, Width - 1, Height - 2), BGColorA, BGColorB, 90);
            G.FillRectangle(bodyGradNone, bodyGradNone.Rectangle);
            LinearGradientBrush bodyInBorderNone = new(new Rectangle(0, 0, Width - 1, Height - 3), BorderColorA, BorderColorB, 90);
            G.DrawRectangle(new(bodyInBorderNone), new Rectangle(1, 1, Width - 3, Height - 4));
            G.DrawRectangle(new(BorderColorC), new Rectangle(0, 0, Width - 1, Height - 2));
            G.DrawLine(new(BorderColorD), new Point(1, Height - 1), new Point(Width - 2, Height - 1));
            DrawTriangle(TriangleColorA, new Point(Width - 14, 8), new Point(Width - 7, 8), new Point(Width - 11, 12), G);
            G.DrawLine(new(TriangleColorB), new Point(Width - 14, 8), new Point(Width - 8, 8));
 
            //Draw Separator line
            G.DrawLine(new(LineColorA), new Point(Width - 22, 1), new Point(Width - 22, Height - 3));
            G.DrawLine(new(LineColorB), new Point(Width - 21, 1), new Point(Width - 21, Height - 3));
            G.DrawLine(new(LineColorC), new Point(Width - 20, 1), new Point(Width - 20, Height - 3));
 
            try
            {
                G.DrawString(Text, Font, new SolidBrush(ForeColor), new Rectangle(5, -1, Width - 20, Height), new StringFormat
                {
                    LineAlignment = StringAlignment.Center,
                    Alignment = StringAlignment.Near
                });
            }
            catch
            {
            }
 
            e.Graphics.DrawImage(B, 0, 0);
            G.Dispose();
            B.Dispose();
        }
    }
 
    #endregion
}