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
#region Imports
 
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region DungeonComboBox
 
    public class DungeonComboBox : ComboBox
    {
        #region Variables
 
        private int _StartIndex = 0;
        private Color _HoverSelectionColor; // VBConversions Note: Initial value cannot be assigned here since it is non-static. Assignment has been moved to the class constructors.
 
        #endregion
 
        #region Custom Properties
 
        public int StartIndex
        {
            get => _StartIndex;
            set
            {
                _StartIndex = value;
                try
                {
                    base.SelectedIndex = value;
                }
                catch
                {
                }
                Invalidate();
            }
        }
 
        public Color HoverSelectionColor
        {
            get => _HoverSelectionColor;
            set
            {
                _HoverSelectionColor = value;
                Invalidate();
            }
        }
 
        public Color ColorA { get; set; } = Color.FromArgb(246, 132, 85);
 
        public Color ColorB { get; set; } = Color.FromArgb(231, 108, 57);
 
        public Color ColorC { get; set; } = Color.FromArgb(242, 241, 240);
 
        public Color ColorD { get; set; } = Color.FromArgb(253, 252, 252);
 
        public Color ColorE { get; set; } = Color.FromArgb(239, 237, 236);
 
        public Color ColorF { get; set; } = Color.FromArgb(180, 180, 180);
 
        public Color ColorG { get; set; } = Color.FromArgb(119, 119, 118);
 
        public Color ColorH { get; set; } = Color.FromArgb(224, 222, 220);
 
        public Color ColorI { get; set; } = Color.FromArgb(250, 249, 249);
 
        #endregion
 
        #region EventArgs
 
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            base.OnDrawItem(e);
            LinearGradientBrush LGB = new(e.Bounds, ColorA, ColorB, 90.0F);
 
            if (Convert.ToInt32(e.State & DrawItemState.Selected) == (int)DrawItemState.Selected)
            {
                if (!(e.Index == -1))
                {
                    e.Graphics.FillRectangle(LGB, e.Bounds);
                    e.Graphics.DrawString(GetItemText(Items[e.Index]), e.Font, Brushes.WhiteSmoke, e.Bounds);
                }
            }
            else
            {
                if (!(e.Index == -1))
                {
                    e.Graphics.FillRectangle(new SolidBrush(ColorC), e.Bounds);
                    e.Graphics.DrawString(GetItemText(Items[e.Index]), e.Font, Brushes.DimGray, e.Bounds);
                }
            }
 
            LGB.Dispose();
        }
 
        protected override void OnLostFocus(EventArgs e)
        {
            base.OnLostFocus(e);
            SuspendLayout();
            Update();
            ResumeLayout();
        }
 
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);
        }
 
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            if (!Focused)
            {
                SelectionLength = 0;
            }
        }
 
        #endregion
 
        public DungeonComboBox()
        {
            SetStyle((ControlStyles)139286, true);
            SetStyle(ControlStyles.Selectable, false);
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
 
            DrawMode = DrawMode.OwnerDrawFixed;
            DropDownStyle = ComboBoxStyle.DropDownList;
 
            BackColor = Color.FromArgb(246, 246, 246);
            ForeColor = Color.FromArgb(76, 76, 97);
            Size = new(135, 26);
            ItemHeight = 20;
            DropDownHeight = 100;
            Font = new("Segoe UI", 10, FontStyle.Regular);
            Cursor = Cursors.Hand;
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
 
            LinearGradientBrush LGB = default;
            GraphicsPath GP = default;
 
            e.Graphics.Clear(Parent.BackColor);
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
 
            // Create a curvy border
            GP = RoundRectangle.RoundRect(0, 0, Width - 1, Height - 1, 5);
 
            // Fills the body of the rectangle with a gradient
            LGB = new(ClientRectangle, ColorD, ColorE, 90.0F);
 
            e.Graphics.SetClip(GP);
            e.Graphics.FillRectangle(LGB, ClientRectangle);
            e.Graphics.ResetClip();
 
            // Draw rectangle border
            e.Graphics.DrawPath(new(ColorF), GP);
 
            // Draw string
            e.Graphics.DrawString(Text, Font, new SolidBrush(ForeColor), new Rectangle(3, 0, Width - 20, Height), new StringFormat
            {
                LineAlignment = StringAlignment.Center,
                Alignment = StringAlignment.Near
            });
 
            e.Graphics.DrawString("6", new Font("Marlett", 13, FontStyle.Regular), new SolidBrush(ColorG), new Rectangle(3, 0, Width - 4, Height), new StringFormat
            {
                LineAlignment = StringAlignment.Center,
                Alignment = StringAlignment.Far
            });
 
            e.Graphics.DrawLine(new(ColorH), Width - 24, 4, Width - 24, Height - 5);
            e.Graphics.DrawLine(new(ColorI), Width - 25, 4, Width - 25, Height - 5);
 
            GP.Dispose();
            LGB.Dispose();
        }
    }
 
    #endregion
}