Dreamine.UI.WinForms
1.0.1
Dreamine.UI.WinForms 사용자 인터페이스 기능과 구성 요소를 제공합니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
DreamineComboBox.cs
이 파일의 문서화 페이지로 가기
1
using
System.Drawing;
2
using
System.Drawing.Drawing2D;
3
using
Dreamine.UI.WinForms
;
4
5
namespace
Dreamine.UI.WinForms.Controls
;
6
15
public
class
DreamineComboBox
: UserControl
16
{
25
private
readonly ComboBox
_inner
;
34
private
bool
_isFocused
;
35
36
// ── Properties ────────────────────────────────────────
45
public
ComboBox.ObjectCollection
Items
=>
_inner
.Items;
46
55
public
object
?
SelectedItem
56
{
57
get
=>
_inner
.SelectedItem;
58
set
=> _inner.SelectedItem = value;
59
}
60
69
public
int
SelectedIndex
70
{
71
get
=>
_inner
.SelectedIndex;
72
set
=> _inner.SelectedIndex = value;
73
}
74
83
public
override
Color
ForeColor
84
{
85
get
=> base.ForeColor;
86
set
{ base.ForeColor = value; _inner.ForeColor = value; }
87
}
88
97
public
new
Font
Font
98
{
99
get
=> base.Font;
100
set
{ base.Font = value; _inner.Font = value; }
101
}
102
111
public
event
EventHandler?
SelectedIndexChanged
;
112
113
// ── Constructor ───────────────────────────────────────
122
public
DreamineComboBox
()
123
{
124
// _inner must be created first — SetStyle / property setters trigger
125
// OnLayout and ForeColor/Font overrides before the field is otherwise set.
126
_inner
=
new
ComboBox
127
{
128
FlatStyle = FlatStyle.Flat,
129
BackColor =
DreamineTheme
.
InputBackground
,
130
ForeColor
=
DreamineTheme
.
TextPrimary
,
131
Font
=
new
Font
(
"Segoe UI"
, 10f, FontStyle.Regular, GraphicsUnit.Point),
132
DropDownStyle = ComboBoxStyle.DropDownList,
133
};
134
135
_inner.GotFocus += (_, _) => {
_isFocused
=
true
; Invalidate(); };
136
_inner.LostFocus += (_, _) => {
_isFocused
=
false
; Invalidate(); };
137
_inner.SelectedIndexChanged += (s, e) =>
SelectedIndexChanged
?.Invoke(
this
, e);
138
_inner.DrawMode = DrawMode.OwnerDrawFixed;
139
_inner.DrawItem +=
OnDrawItem
;
140
141
SetStyle(
142
ControlStyles.AllPaintingInWmPaint |
143
ControlStyles.UserPaint |
144
ControlStyles.DoubleBuffer |
145
ControlStyles.ResizeRedraw,
true
);
146
147
BackColor =
DreamineTheme
.
InputBackground
;
148
ForeColor
=
DreamineTheme
.
TextPrimary
;
149
Font
=
_inner
.Font;
150
Height = 36;
151
152
Controls
.Add(
_inner
);
153
}
154
171
protected
override
void
OnLayout
(LayoutEventArgs e)
172
{
173
base.OnLayout(e);
174
if
(
_inner
==
null
)
return
;
175
_inner
.SetBounds(0, (Height -
_inner
.PreferredHeight) / 2,
176
Width,
_inner
.PreferredHeight);
177
}
178
203
private
void
OnDrawItem
(
object
? sender, DrawItemEventArgs e)
204
{
205
if
(e.Index < 0)
return
;
206
var isSelected = (e.State & DrawItemState.Selected) != 0;
207
var isHover = (e.State & DrawItemState.HotLight) != 0;
208
209
var bg = isSelected
210
?
DreamineTheme.AccentBlue
211
: isHover
212
? Color.FromArgb(0xFF, 0x1E, 0x4A, 0x80)
213
:
DreamineTheme
.
InputBackground
;
214
215
using
var bgBrush =
new
SolidBrush(bg);
216
e.Graphics.FillRectangle(bgBrush, e.Bounds);
217
218
string
? text =
_inner
.Items[e.Index]?.ToString();
219
if
(!
string
.IsNullOrEmpty(text))
220
{
221
using
var textBrush =
new
SolidBrush(
DreamineTheme
.
TextPrimary
);
222
var sf =
new
StringFormat { LineAlignment = StringAlignment.Center };
223
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
224
e.Graphics.DrawString(text, e.Font!, textBrush,
225
new
Rectangle(e.Bounds.X + 6, e.Bounds.Y, e.Bounds.Width - 6, e.Bounds.Height), sf);
226
}
227
}
228
245
protected
override
void
OnPaint
(PaintEventArgs e)
246
{
247
var g = e.Graphics;
248
var rect =
new
Rectangle(0, 0, Width - 1, Height - 1);
249
using
var bgBrush =
new
SolidBrush(BackColor);
250
var borderColor =
_isFocused
?
DreamineTheme.BorderFocus
:
DreamineTheme
.
BorderNormal
;
251
using
var pen =
new
Pen(borderColor, 1.5f);
252
DreamineDrawHelper
.
FillRoundedRect
(g, bgBrush, pen, rect,
DreamineTheme
.
CornerRadiusSmall
);
253
}
254
263
protected
override
Size
DefaultSize
=>
new
(200, 36);
264
}
Dreamine.UI.WinForms
Definition
DreamineButton.cs:6
Dreamine.UI.WinForms.Controls
Definition
DreamineButton.cs:6
Dreamine.UI.WinForms.Controls.DreamineComboBox.OnPaint
override void OnPaint(PaintEventArgs e)
Definition
DreamineComboBox.cs:245
Dreamine.UI.WinForms.Controls.DreamineComboBox.SelectedItem
object? SelectedItem
Definition
DreamineComboBox.cs:56
Dreamine.UI.WinForms.Controls.DreamineComboBox._inner
readonly ComboBox _inner
Definition
DreamineComboBox.cs:25
Dreamine.UI.WinForms.Controls.DreamineComboBox._isFocused
bool _isFocused
Definition
DreamineComboBox.cs:34
Dreamine.UI.WinForms.Controls.DreamineComboBox.OnLayout
override void OnLayout(LayoutEventArgs e)
Definition
DreamineComboBox.cs:171
Dreamine.UI.WinForms.Controls.DreamineComboBox.DefaultSize
override Size DefaultSize
Definition
DreamineComboBox.cs:263
Dreamine.UI.WinForms.Controls.DreamineComboBox.SelectedIndex
int SelectedIndex
Definition
DreamineComboBox.cs:70
Dreamine.UI.WinForms.Controls.DreamineComboBox.SelectedIndexChanged
EventHandler? SelectedIndexChanged
Definition
DreamineComboBox.cs:111
Dreamine.UI.WinForms.Controls.DreamineComboBox.Items
ComboBox.ObjectCollection Items
Definition
DreamineComboBox.cs:45
Dreamine.UI.WinForms.Controls.DreamineComboBox.DreamineComboBox
DreamineComboBox()
Definition
DreamineComboBox.cs:122
Dreamine.UI.WinForms.Controls.DreamineComboBox.Font
new Font Font
Definition
DreamineComboBox.cs:98
Dreamine.UI.WinForms.Controls.DreamineComboBox.OnDrawItem
void OnDrawItem(object? sender, DrawItemEventArgs e)
Definition
DreamineComboBox.cs:203
Dreamine.UI.WinForms.Controls.DreamineComboBox.ForeColor
override Color ForeColor
Definition
DreamineComboBox.cs:84
Dreamine.UI.WinForms.DreamineDrawHelper
Definition
DreamineDrawHelper.cs:15
Dreamine.UI.WinForms.DreamineDrawHelper.FillRoundedRect
static void FillRoundedRect(Graphics g, Brush fill, Pen? border, Rectangle rect, float radius)
Definition
DreamineDrawHelper.cs:144
Dreamine.UI.WinForms.DreamineTheme
Definition
DreamineTheme.cs:14
Dreamine.UI.WinForms.DreamineTheme.CornerRadiusSmall
const int CornerRadiusSmall
Definition
DreamineTheme.cs:225
Dreamine.UI.WinForms.DreamineTheme.BorderFocus
static readonly Color BorderFocus
Definition
DreamineTheme.cs:80
Dreamine.UI.WinForms.DreamineTheme.TextPrimary
static readonly Color TextPrimary
Definition
DreamineTheme.cs:91
Dreamine.UI.WinForms.DreamineTheme.BorderNormal
static readonly Color BorderNormal
Definition
DreamineTheme.cs:71
Dreamine.UI.WinForms.DreamineTheme.AccentBlue
static readonly Color AccentBlue
Definition
DreamineTheme.cs:129
Dreamine.UI.WinForms.DreamineTheme.InputBackground
static readonly Color InputBackground
Definition
DreamineTheme.cs:42
Controls
DreamineComboBox.cs
다음에 의해 생성됨 :
1.17.0