Dreamine.UI.WinForms 1.0.1
Dreamine.UI.WinForms 사용자 인터페이스 기능과 구성 요소를 제공합니다.
로딩중...
검색중...
일치하는것 없음
DreamineCheckBox.cs
이 파일의 문서화 페이지로 가기
1using System.Drawing;
2using System.Drawing.Drawing2D;
4
6
15public 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
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))
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
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}
static void FillRoundedRect(Graphics g, Brush fill, Pen? border, Rectangle rect, float radius)
static Color Blend(Color base_, Color overlay, float alpha)
static readonly Color TextSecondary
static readonly Color BorderFocus
static readonly Color TextPrimary
static readonly Color BorderNormal
static readonly Color InputBackground