-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSkeetComboBox.cs
More file actions
171 lines (144 loc) · 5.36 KB
/
SkeetComboBox.cs
File metadata and controls
171 lines (144 loc) · 5.36 KB
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SkeetFramework
{
public class SkeetComboBox : ComboBox
{
private int W;
private int H;
private int _StartIndex = 0;
private int x;
private int y;
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
Invalidate();
}
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
Invalidate();
}
protected override void OnMouseEnter(EventArgs e)
{
base.OnMouseEnter(e);
Invalidate();
}
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
Invalidate();
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
x = e.Location.X;
y = e.Location.Y;
Invalidate();
if (e.X < Width - 41)
Cursor = Cursors.IBeam;
else
Cursor = Cursors.Hand;
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
base.OnDrawItem(e);
Invalidate();
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
Invalidate();
}
}
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
Invalidate();
}
private int StartIndex
{
get { return _StartIndex; }
set
{
_StartIndex = value;
try
{
base.SelectedIndex = value;
}
catch
{
}
Invalidate();
}
}
public void DrawItem_(System.Object sender, System.Windows.Forms.DrawItemEventArgs e)
{
if (e.Index < 0)
return;
e.DrawBackground();
e.DrawFocusRectangle();
e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
//-- Selected item
e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(25,25,25)), e.Bounds);
}
else
{
//-- Not Selected
e.Graphics.FillRectangle(new SolidBrush(_BaseColor), e.Bounds);
}
//-- Text
e.Graphics.DrawString(base.GetItemText(base.Items[e.Index]), new Font("Segoe UI", 8), Brushes.White, new Rectangle(e.Bounds.X + 2, e.Bounds.Y + 2, e.Bounds.Width, e.Bounds.Height));
e.Graphics.Dispose();
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
Height = 18;
}
private Color _BaseColor = Color.FromArgb(25, 27, 29);
private Color _BGColor = Color.FromArgb(45, 47, 49);
//private Color _HoverColor = Color.FromArgb(35, 168, 109);
public SkeetComboBox()
{
DrawItem += DrawItem_;
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer, true);
DoubleBuffered = true;
DrawMode = DrawMode.OwnerDrawFixed;
BackColor = Color.FromArgb(45, 45, 48);
ForeColor = Color.White;
DropDownStyle = ComboBoxStyle.DropDownList;
Cursor = Cursors.Hand;
StartIndex = 0;
ItemHeight = 18;
Font = new Font("Segoe UI", 8, FontStyle.Regular);
}
public Color ColorTop { get; set; } = Color.FromArgb(23, 23, 23);
public Color ColorBottom { get; set; } = Color.FromArgb(25, 25, 25);
private bool active = false;
private StringFormat strFormat = new StringFormat();
public Pen FakeWhite { get; set; } = new Pen(Color.FromArgb(50, 50, 50));
protected override void OnPaint(PaintEventArgs e)
{
Rectangle ree = new Rectangle(0, 0, Width - 1, Height - 1);
Rectangle ree2 = new Rectangle(1, 1, Width - 3, Height - 3);
LinearGradientBrush gradient = new LinearGradientBrush(ree, this.ColorBottom, this.ColorTop, 90.0f);
e.Graphics.FillRectangle(gradient, ree);
e.Graphics.DrawRectangle(Pens.Black, ree);
e.Graphics.DrawRectangle(FakeWhite, ree2);
e.Graphics.DrawString(Text, Font, Brushes.White , new Point(4, 6));
e.Graphics.DrawString("v", new Font("Verdana", 7), Brushes.White, new Point(Width - 15 , 6));
}
}
}