Dreamine.UI.WinForms 1.0.1
Dreamine.UI.WinForms 사용자 인터페이스 기능과 구성 요소를 제공합니다.
로딩중...
검색중...
일치하는것 없음
DreamineListBox.cs
이 파일의 문서화 페이지로 가기
1using System.Drawing;
3
5
14public class DreamineListBox : UserControl
15{
24 private readonly ListBox _inner;
33 private bool _isFocused;
34
43 public ListBox.ObjectCollection Items => _inner.Items;
44
53 public object? SelectedItem
54 {
55 get => _inner.SelectedItem;
56 set => _inner.SelectedItem = value;
57 }
58
67 public int SelectedIndex
68 {
69 get => _inner.SelectedIndex;
70 set => _inner.SelectedIndex = value;
71 }
72
81 public object? DataSource
82 {
83 get => _inner.DataSource;
84 set => _inner.DataSource = value;
85 }
86
95 public override Color ForeColor
96 {
97 get => base.ForeColor;
98 set { base.ForeColor = value; _inner.ForeColor = value; }
99 }
100
109 public new Font Font
110 {
111 get => base.Font;
112 set { base.Font = value; _inner.Font = value; }
113 }
114
123 public event EventHandler? SelectedIndexChanged;
132 public new event MouseEventHandler? DoubleClick
133 {
134 add => _inner.MouseDoubleClick += value;
135 remove => _inner.MouseDoubleClick -= value;
136 }
137
146 public bool AutoScrollToEnd { get; set; }
147
157 {
158 _inner = new ListBox
159 {
160 BorderStyle = BorderStyle.None,
161 // IntegralHeight=true(기본값)면 마지막 줄이 잘릴 때 빈 띠를 남겨버려서
162 // Dock=Fill로 크기를 강제로 맞추는 우리 사용 패턴과 충돌한다.
163 IntegralHeight = false,
164 BackColor = DreamineTheme.InputBackground,
166 Font = new Font("Segoe UI", 10f, FontStyle.Regular, GraphicsUnit.Point),
167 Dock = DockStyle.Fill,
168 };
169
170 _inner.GotFocus += (_, _) => { _isFocused = true; Invalidate(); };
171 _inner.LostFocus += (_, _) => { _isFocused = false; Invalidate(); };
172 _inner.SelectedIndexChanged += (s, e) =>
173 {
174 SelectedIndexChanged?.Invoke(this, e);
175 if (AutoScrollToEnd && _inner.Items.Count > 0)
176 _inner.TopIndex = _inner.Items.Count - 1;
177 };
178
179 SetStyle(
180 ControlStyles.AllPaintingInWmPaint |
181 ControlStyles.UserPaint |
182 ControlStyles.DoubleBuffer |
183 ControlStyles.ResizeRedraw, true);
184
185 BackColor = DreamineTheme.InputBackground;
187 Font = _inner.Font;
188 Padding = new Padding(2);
189
190 Controls.Add(_inner);
191 }
192
201 public void NotifyItemAdded()
202 {
203 if (AutoScrollToEnd && _inner.Items.Count > 0)
204 _inner.TopIndex = _inner.Items.Count - 1;
205 }
206
223 protected override void OnPaint(PaintEventArgs e)
224 {
225 var g = e.Graphics;
226 var rect = new Rectangle(0, 0, Width - 1, Height - 1);
227 using var bgBrush = new SolidBrush(BackColor);
229 using var pen = new Pen(borderColor, 1.5f);
231 }
232
241 protected override Size DefaultSize => new(220, 100);
242}
override void OnPaint(PaintEventArgs e)
static void FillRoundedRect(Graphics g, Brush fill, Pen? border, Rectangle rect, float radius)
static readonly Color BorderFocus
static readonly Color TextPrimary
static readonly Color BorderNormal
static readonly Color InputBackground