Dreamine.UI.WinForms 1.0.1
Dreamine.UI.WinForms 사용자 인터페이스 기능과 구성 요소를 제공합니다.
로딩중...
검색중...
일치하는것 없음
BlinkPopupForm.cs
이 파일의 문서화 페이지로 가기
1using System.Collections.Generic;
2using System.Drawing;
3using System.Windows.Forms;
5
7
16internal sealed class BlinkPopupForm : Form
17{
26 private readonly BlinkPopupOptions _options;
35 private readonly System.Windows.Forms.Timer? _blinkTimer;
44 private bool _blinkPhase;
53 private readonly List<DreamineButton> _blinkButtons = new();
54
63 public DialogResult Result { get; private set; } = DialogResult.Cancel;
64
89 public BlinkPopupForm(BlinkPopupOptions options)
90 {
91 _options = options;
92
93 FormBorderStyle = FormBorderStyle.None;
94 StartPosition = FormStartPosition.CenterScreen;
95 Size = new Size(480, 260);
96 ShowInTaskbar = false;
97 TopMost = true;
98 BackColor = options.Color1;
99 // 자식 컨트롤이 Form 가장자리까지 꽉 채우면 WS_CLIPCHILDREN 때문에 그 부분의
100 // 테두리가 안 그려진다(자식이 덮은 영역은 Form의 OnPaint가 그릴 수 없음).
101 // Padding으로 살짝 여백을 둬서 가장자리 전체에 테두리가 끊김 없이 그려지게 한다.
102 Padding = new Padding(2);
103
104 var titleLabel = new Label
105 {
106 Text = options.Title ?? string.Empty,
107 ForeColor = options.ForegroundColor,
108 Font = new Font("Segoe UI", 20f, FontStyle.Bold),
109 Dock = DockStyle.Top,
110 Height = 64,
111 TextAlign = ContentAlignment.MiddleCenter
112 };
113
114 var messageLabel = new Label
115 {
116 Text = options.Message ?? string.Empty,
117 ForeColor = options.ForegroundColor,
118 Font = new Font("Segoe UI", 12f),
119 Dock = DockStyle.Fill,
120 TextAlign = ContentAlignment.MiddleCenter
121 };
122
123 var buttonPanel = new FlowLayoutPanel
124 {
125 Dock = DockStyle.Bottom,
126 Height = 64,
127 FlowDirection = FlowDirection.RightToLeft,
128 Padding = new Padding(0, 0, 16, 16),
129 BackColor = Color.Transparent
130 };
131
132 if (!string.IsNullOrEmpty(options.OkText))
133 {
134 var okButton = new DreamineButton { Content = options.OkText, Width = 110, Height = 36, CornerRadius = 6, Margin = new Padding(8, 12, 0, 0) };
135 okButton.MouseUp += (_, e) =>
136 {
137 if (e.Button == MouseButtons.Left && okButton.ClientRectangle.Contains(e.Location))
138 {
139 Result = DialogResult.OK;
140 Close();
141 }
142 };
143 buttonPanel.Controls.Add(okButton);
144 _blinkButtons.Add(okButton);
145 }
146
147 if (!string.IsNullOrEmpty(options.CancelText))
148 {
149 var cancelButton = new DreamineButton { Content = options.CancelText, Width = 110, Height = 36, CornerRadius = 6, Margin = new Padding(8, 12, 0, 0) };
150 cancelButton.MouseUp += (_, e) =>
151 {
152 if (e.Button == MouseButtons.Left && cancelButton.ClientRectangle.Contains(e.Location))
153 {
154 Result = DialogResult.Cancel;
155 Close();
156 }
157 };
158 buttonPanel.Controls.Add(cancelButton);
159 _blinkButtons.Add(cancelButton);
160 }
161
162 Controls.Add(buttonPanel);
163 Controls.Add(messageLabel);
164 Controls.Add(titleLabel);
165
166 if (options.UseBlink)
167 {
168 var buttonBaseColor = DreamineTheme.NavBackground;
169
170 _blinkTimer = new System.Windows.Forms.Timer { Interval = options.BlinkIntervalMs };
171 _blinkTimer.Tick += (_, _) =>
172 {
173 _blinkPhase = !_blinkPhase;
174 var phaseColor = _blinkPhase ? options.Color2 : options.Color1;
175 BackColor = phaseColor;
176
177 // 버튼도 같은 박자로 살짝 색이 묻어나게 해서 배경 점멸과 시각적으로 맞물리게 한다.
178 var tinted = DreamineDrawHelper.Blend(buttonBaseColor, phaseColor, 0.35f);
179 foreach (var btn in _blinkButtons)
180 btn.BackColor = tinted;
181 };
182 _blinkTimer.Start();
183 }
184 }
185
202 protected override void OnPaint(PaintEventArgs e)
203 {
204 base.OnPaint(e);
205 // Form 자체를 Region으로 둥글게 잘라내면 GDI Region 특성상 안티앨리어싱이 없어
206 // 오히려 거칠게 보인다(데스크톱이 뒤로 보여야 해서 버튼처럼 "부모색 채우기"로
207 // 대체할 수도 없음). 그래서 Form은 사각형을 유지하고, 차분한 반투명 흰색 테두리만
208 // 그려서 깔끔하게 마무리한다.
209 using var pen = new Pen(Color.FromArgb(90, 255, 255, 255), 1.5f);
210 e.Graphics.DrawRectangle(pen, 0, 0, Width - 1, Height - 1);
211 }
212
229 protected override void Dispose(bool disposing)
230 {
231 if (disposing)
232 _blinkTimer?.Dispose();
233 base.Dispose(disposing);
234 }
235}
static Color Blend(Color base_, Color overlay, float alpha)
static readonly Color NavBackground