Dreamine.UI.WinForms 1.0.1
Dreamine.UI.WinForms 사용자 인터페이스 기능과 구성 요소를 제공합니다.
로딩중...
검색중...
일치하는것 없음
DreamineExpander.cs
이 파일의 문서화 페이지로 가기
1using System.Drawing;
2using System.Drawing.Drawing2D;
4
6
15public class DreamineExpander : UserControl
16{
25 private readonly Panel _headerPanel;
34 private readonly Label _headerLabel;
43 private readonly Label _arrowLabel;
52 private readonly Panel _contentPanel;
61 private int _expandedHeight;
62
71 private const int HeaderHeight = 36;
72
73 // ── Properties ────────────────────────────────────────
82 private string _header = string.Empty;
91 public string Header
92 {
93 get => _header;
94 set { _header = value; _headerLabel.Text = value; }
95 }
96
105 private bool _isExpanded = true;
114 public bool IsExpanded
115 {
116 get => _isExpanded;
117 set
118 {
119 if (_isExpanded == value) return;
120 _isExpanded = value;
122 ExpandedChanged?.Invoke(this, EventArgs.Empty);
123 }
124 }
125
134 public Panel Content => _contentPanel;
135
144 public event EventHandler? ExpandedChanged;
145
146 // ── Constructor ───────────────────────────────────────
156 {
157 SetStyle(
158 ControlStyles.AllPaintingInWmPaint |
159 ControlStyles.UserPaint |
160 ControlStyles.DoubleBuffer |
161 ControlStyles.ResizeRedraw, true);
162
163 BackColor = DreamineTheme.CardBackground;
164 ForeColor = DreamineTheme.TextPrimary;
165 Font = new Font("Segoe UI", 10f, FontStyle.Regular, GraphicsUnit.Point);
166
167 // Header
168 _headerPanel = new Panel
169 {
170 Dock = DockStyle.Top,
171 Height = HeaderHeight,
172 BackColor = DreamineTheme.CardBackground,
173 Cursor = Cursors.Hand,
174 };
175
176 _arrowLabel = new Label
177 {
178 Text = "▼",
179 ForeColor = DreamineTheme.TextSecondary,
180 Font = new Font("Segoe UI", 8f, FontStyle.Regular, GraphicsUnit.Point),
181 AutoSize = false,
182 Width = 20,
183 TextAlign = ContentAlignment.MiddleCenter,
184 Dock = DockStyle.Left,
185 BackColor = Color.Transparent,
186 };
187
188 _headerLabel = new Label
189 {
190 Text = _header,
191 ForeColor = DreamineTheme.TextPrimary,
192 Font = new Font("Segoe UI", 10f, FontStyle.Bold, GraphicsUnit.Point),
193 AutoSize = false,
194 Dock = DockStyle.Fill,
195 TextAlign = ContentAlignment.MiddleLeft,
196 Padding = new Padding(4, 0, 0, 0),
197 BackColor = Color.Transparent,
198 };
199
200 _headerPanel.Controls.Add(_headerLabel);
201 _headerPanel.Controls.Add(_arrowLabel);
202
203 _headerPanel.Click += OnHeaderClick;
204 _headerLabel.Click += OnHeaderClick;
205 _arrowLabel.Click += OnHeaderClick;
206
207 // Content
208 _contentPanel = new Panel
209 {
210 Dock = DockStyle.Fill,
211 BackColor = DreamineTheme.CardBackground,
212 Padding = new Padding(8),
213 };
214
217
218 _expandedHeight = 120;
219 Height = HeaderHeight + _expandedHeight;
220 }
221
246 private void OnHeaderClick(object? s, EventArgs e)
247 {
249 }
250
259 private void ApplyExpandState()
260 {
261 if (_isExpanded)
262 {
263 _arrowLabel.Text = "▼";
264 _contentPanel.Visible = true;
265 Height = HeaderHeight + _expandedHeight;
266 }
267 else
268 {
269 _arrowLabel.Text = "▶";
270 _expandedHeight = Height - HeaderHeight;
271 _contentPanel.Visible = false;
272 Height = HeaderHeight;
273 }
274 }
275
292 protected override void OnPaint(PaintEventArgs e)
293 {
294 var g = e.Graphics;
295 var rect = new Rectangle(0, 0, Width - 1, Height - 1);
296 using var bgBrush = new SolidBrush(BackColor);
297 using var borderPen = new Pen(DreamineTheme.BorderNormal, 1f);
298 DreamineDrawHelper.FillRoundedRect(g, bgBrush, borderPen, rect, DreamineTheme.CornerRadius);
299
300 // Header separator line
301 if (_isExpanded)
302 {
303 using var divPen = new Pen(DreamineTheme.BorderNormal, 1f);
304 g.DrawLine(divPen, 0, HeaderHeight, Width, HeaderHeight);
305 }
306 }
307
316 protected override Size DefaultSize => new(400, 120);
317}
static void FillRoundedRect(Graphics g, Brush fill, Pen? border, Rectangle rect, float radius)
static readonly Color TextSecondary
static readonly Color CardBackground
static readonly Color TextPrimary
static readonly Color BorderNormal