Dreamine.UI.WinForms
1.0.1
Dreamine.UI.WinForms 사용자 인터페이스 기능과 구성 요소를 제공합니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
DreamineCheckBox.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
DreamineCheckBox
: Control
16
{
25
private
bool
_isHover
;
34
private
bool
_isChecked
;
35
44
public
bool
IsChecked
45
{
46
get
=>
_isChecked
;
47
set
48
{
49
if
(
_isChecked
== value)
return
;
50
_isChecked
= value;
51
Invalidate();
52
CheckedChanged
?.Invoke(
this
, EventArgs.Empty);
53
}
54
}
55
64
private
string
_content
=
string
.Empty;
73
public
string
Content
74
{
75
get
=>
_content
;
76
set
{
_content
= value; Invalidate(); }
77
}
78
87
public
event
EventHandler?
CheckedChanged
;
88
97
private
const
int
BoxSize
= 16;
106
private
const
int
BoxMargin
= 2;
107
116
public
DreamineCheckBox
()
117
{
118
SetStyle(
119
ControlStyles.AllPaintingInWmPaint |
120
ControlStyles.UserPaint |
121
ControlStyles.DoubleBuffer |
122
ControlStyles.ResizeRedraw |
123
ControlStyles.SupportsTransparentBackColor,
true
);
124
125
BackColor = Color.Transparent;
126
ForeColor =
DreamineTheme
.
TextPrimary
;
127
Font =
new
Font(
"Segoe UI"
, 10f, FontStyle.Regular, GraphicsUnit.Point);
128
Height = 24;
129
Cursor = Cursors.Hand;
130
}
131
148
protected
override
void
OnMouseEnter
(EventArgs e) { base.OnMouseEnter(e);
_isHover
=
true
; Invalidate(); }
165
protected
override
void
OnMouseLeave
(EventArgs e) { base.OnMouseLeave(e);
_isHover
=
false
; Invalidate(); }
166
183
protected
override
void
OnMouseUp
(MouseEventArgs e)
184
{
185
base.OnMouseUp(e);
186
if
(Enabled && e.Button == MouseButtons.Left && ClientRectangle.Contains(e.Location))
187
IsChecked
= !
IsChecked
;
188
}
189
206
protected
override
void
OnPaint
(PaintEventArgs e)
207
{
208
var g = e.Graphics;
209
g.SmoothingMode = SmoothingMode.AntiAlias;
210
211
int
x =
BoxMargin
, y = (Height -
BoxSize
) / 2;
212
var boxRect =
new
Rectangle(x, y,
BoxSize
,
BoxSize
);
213
214
// Box background
215
var bg =
_isChecked
216
?
DreamineTheme.AccentBlue
217
:
DreamineTheme
.
InputBackground
;
218
if
(
_isHover
&& !
_isChecked
)
219
bg =
DreamineDrawHelper
.
Blend
(bg, Color.White, 0.1f);
220
221
using
var bgBrush =
new
SolidBrush(bg);
222
using
var borderPen =
new
Pen(
_isHover
||
_isChecked
?
DreamineTheme
.
BorderFocus
:
DreamineTheme
.
BorderNormal
, 1.5f);
223
DreamineDrawHelper
.
FillRoundedRect
(g, bgBrush, borderPen, boxRect, 3f);
224
225
// Checkmark
226
if
(
_isChecked
)
227
{
228
using
var ckPen =
new
Pen(Color.White, 2f) { LineJoin = LineJoin.Round };
229
int
cx = x + 3, cy = y +
BoxSize
/ 2;
230
g.DrawLines(ckPen,
new
[]
231
{
232
new
Point(cx, cy),
233
new
Point(cx + 3, cy + 3),
234
new
Point(cx + 8, cy - 3)
235
});
236
}
237
238
// Label text
239
using
var brush =
new
SolidBrush(Enabled ? ForeColor :
DreamineTheme
.
TextSecondary
);
240
int
textX =
BoxMargin
+
BoxSize
+ 6;
241
var textRect =
new
Rectangle(textX, 0, Width - textX, Height);
242
var sf =
new
StringFormat { LineAlignment = StringAlignment.Center };
243
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
244
g.DrawString(
_content
, Font, brush, textRect, sf);
245
}
246
255
protected
override
Size
DefaultSize
=>
new
(160, 24);
256
}
Dreamine.UI.WinForms
Definition
DreamineButton.cs:6
Dreamine.UI.WinForms.Controls
Definition
DreamineButton.cs:6
Dreamine.UI.WinForms.Controls.DreamineCheckBox._isHover
bool _isHover
Definition
DreamineCheckBox.cs:25
Dreamine.UI.WinForms.Controls.DreamineCheckBox.BoxMargin
const int BoxMargin
Definition
DreamineCheckBox.cs:106
Dreamine.UI.WinForms.Controls.DreamineCheckBox.DefaultSize
override Size DefaultSize
Definition
DreamineCheckBox.cs:255
Dreamine.UI.WinForms.Controls.DreamineCheckBox._content
string _content
Definition
DreamineCheckBox.cs:64
Dreamine.UI.WinForms.Controls.DreamineCheckBox.IsChecked
bool IsChecked
Definition
DreamineCheckBox.cs:45
Dreamine.UI.WinForms.Controls.DreamineCheckBox.DreamineCheckBox
DreamineCheckBox()
Definition
DreamineCheckBox.cs:116
Dreamine.UI.WinForms.Controls.DreamineCheckBox.OnMouseLeave
override void OnMouseLeave(EventArgs e)
Definition
DreamineCheckBox.cs:165
Dreamine.UI.WinForms.Controls.DreamineCheckBox.OnMouseUp
override void OnMouseUp(MouseEventArgs e)
Definition
DreamineCheckBox.cs:183
Dreamine.UI.WinForms.Controls.DreamineCheckBox.BoxSize
const int BoxSize
Definition
DreamineCheckBox.cs:97
Dreamine.UI.WinForms.Controls.DreamineCheckBox.CheckedChanged
EventHandler? CheckedChanged
Definition
DreamineCheckBox.cs:87
Dreamine.UI.WinForms.Controls.DreamineCheckBox.OnPaint
override void OnPaint(PaintEventArgs e)
Definition
DreamineCheckBox.cs:206
Dreamine.UI.WinForms.Controls.DreamineCheckBox.OnMouseEnter
override void OnMouseEnter(EventArgs e)
Definition
DreamineCheckBox.cs:148
Dreamine.UI.WinForms.Controls.DreamineCheckBox.Content
string Content
Definition
DreamineCheckBox.cs:74
Dreamine.UI.WinForms.Controls.DreamineCheckBox._isChecked
bool _isChecked
Definition
DreamineCheckBox.cs:34
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.DreamineDrawHelper.Blend
static Color Blend(Color base_, Color overlay, float alpha)
Definition
DreamineDrawHelper.cs:373
Dreamine.UI.WinForms.DreamineTheme
Definition
DreamineTheme.cs:14
Dreamine.UI.WinForms.DreamineTheme.TextSecondary
static readonly Color TextSecondary
Definition
DreamineTheme.cs:100
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
DreamineCheckBox.cs
다음에 의해 생성됨 :
1.17.0