Dreamine.UI.WinForms
1.0.1
Dreamine.UI.WinForms 사용자 인터페이스 기능과 구성 요소를 제공합니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
DreaminePasswordBox.cs
이 파일의 문서화 페이지로 가기
1
using
System.Drawing;
2
using
System.Runtime.InteropServices;
3
using
Dreamine.UI.WinForms
;
4
5
namespace
Dreamine.UI.WinForms.Controls
;
6
15
public
class
DreaminePasswordBox
: UserControl
16
{
25
private
const
int
EM_SETCUEBANNER
= 0x1501;
74
[DllImport(
"user32.dll"
, CharSet = CharSet.Unicode)]
75
private
static
extern
IntPtr
SendMessage
(IntPtr hWnd,
int
msg, IntPtr wParam,
string
lParam);
76
85
private
readonly TextBox
_inner
;
94
private
bool
_isFocused
;
95
96
// ── Properties ────────────────────────────────────────
105
public
string
Password
106
{
107
get
=>
_inner
.Text;
108
set
=> _inner.Text = value;
109
}
110
119
private
string
_hint
=
string
.Empty;
128
public
string
Hint
129
{
130
get
=>
_hint
;
131
set
132
{
133
_hint
= value;
134
if
(
_inner
.IsHandleCreated)
135
SendMessage
(
_inner
.Handle,
EM_SETCUEBANNER
, (IntPtr)1,
_hint
);
136
}
137
}
138
147
public
override
Color
ForeColor
148
{
149
get
=> base.ForeColor;
150
set
{ base.ForeColor = value;
if
(
_inner
!=
null
) _inner.ForeColor = value; }
151
}
152
161
public
new
Font
Font
162
{
163
get
=> base.Font;
164
set
{ base.Font = value;
if
(
_inner
!=
null
) _inner.Font = value; }
165
}
166
175
public
event
EventHandler?
PasswordChanged
;
176
177
// ── Constructor ───────────────────────────────────────
186
public
DreaminePasswordBox
()
187
{
188
// _inner must be created first — SetStyle and property setters below
189
// can trigger OnLayout / ForeColor / Font overrides before the field is set.
190
_inner
=
new
TextBox
191
{
192
BorderStyle = BorderStyle.None,
193
BackColor =
DreamineTheme
.
InputBackground
,
194
ForeColor
=
DreamineTheme
.
TextPrimary
,
195
Font
=
new
Font
(
"Segoe UI"
, 10f, FontStyle.Regular, GraphicsUnit.Point),
196
UseSystemPasswordChar =
true
,
197
};
198
199
_inner.GotFocus += (_, _) => {
_isFocused
=
true
; Invalidate(); };
200
_inner.LostFocus += (_, _) => {
_isFocused
=
false
; Invalidate(); };
201
_inner.TextChanged += (s, e) =>
PasswordChanged
?.Invoke(
this
, e);
202
_inner.HandleCreated += (_, _) =>
203
{
204
if
(!
string
.IsNullOrEmpty(
_hint
))
205
SendMessage
(
_inner
.Handle,
EM_SETCUEBANNER
, (IntPtr)1,
_hint
);
206
};
207
208
SetStyle(
209
ControlStyles.AllPaintingInWmPaint |
210
ControlStyles.UserPaint |
211
ControlStyles.DoubleBuffer |
212
ControlStyles.ResizeRedraw,
true
);
213
214
BackColor =
DreamineTheme
.
InputBackground
;
215
ForeColor
=
DreamineTheme
.
TextPrimary
;
216
Font
=
_inner
.Font;
217
Height = 36;
218
219
Controls
.Add(
_inner
);
220
}
221
238
protected
override
void
OnLayout
(LayoutEventArgs e)
239
{
240
base.OnLayout(e);
241
if
(
_inner
==
null
)
return
;
242
_inner
.SetBounds(6, (Height -
_inner
.PreferredHeight) / 2,
243
Width - 12,
_inner
.PreferredHeight);
244
}
245
262
protected
override
void
OnPaint
(PaintEventArgs e)
263
{
264
var g = e.Graphics;
265
var rect =
new
Rectangle(0, 0, Width - 1, Height - 1);
266
using
var bgBrush =
new
SolidBrush(BackColor);
267
var borderColor =
_isFocused
?
DreamineTheme.BorderFocus
:
DreamineTheme
.
BorderNormal
;
268
using
var pen =
new
Pen(borderColor, 1.5f);
269
DreamineDrawHelper
.
FillRoundedRect
(g, bgBrush, pen, rect,
DreamineTheme
.
CornerRadiusSmall
);
270
}
271
280
protected
override
Size
DefaultSize
=>
new
(220, 36);
281
}
Dreamine.UI.WinForms
Definition
DreamineButton.cs:6
Dreamine.UI.WinForms.Controls
Definition
DreamineButton.cs:6
Dreamine.UI.WinForms.Controls.DreaminePasswordBox._isFocused
bool _isFocused
Definition
DreaminePasswordBox.cs:94
Dreamine.UI.WinForms.Controls.DreaminePasswordBox.SendMessage
static IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, string lParam)
Dreamine.UI.WinForms.Controls.DreaminePasswordBox.Font
new Font Font
Definition
DreaminePasswordBox.cs:162
Dreamine.UI.WinForms.Controls.DreaminePasswordBox.OnLayout
override void OnLayout(LayoutEventArgs e)
Definition
DreaminePasswordBox.cs:238
Dreamine.UI.WinForms.Controls.DreaminePasswordBox.DefaultSize
override Size DefaultSize
Definition
DreaminePasswordBox.cs:280
Dreamine.UI.WinForms.Controls.DreaminePasswordBox.OnPaint
override void OnPaint(PaintEventArgs e)
Definition
DreaminePasswordBox.cs:262
Dreamine.UI.WinForms.Controls.DreaminePasswordBox.Password
string Password
Definition
DreaminePasswordBox.cs:106
Dreamine.UI.WinForms.Controls.DreaminePasswordBox._hint
string _hint
Definition
DreaminePasswordBox.cs:119
Dreamine.UI.WinForms.Controls.DreaminePasswordBox.EM_SETCUEBANNER
const int EM_SETCUEBANNER
Definition
DreaminePasswordBox.cs:25
Dreamine.UI.WinForms.Controls.DreaminePasswordBox._inner
readonly TextBox _inner
Definition
DreaminePasswordBox.cs:85
Dreamine.UI.WinForms.Controls.DreaminePasswordBox.ForeColor
override Color ForeColor
Definition
DreaminePasswordBox.cs:148
Dreamine.UI.WinForms.Controls.DreaminePasswordBox.DreaminePasswordBox
DreaminePasswordBox()
Definition
DreaminePasswordBox.cs:186
Dreamine.UI.WinForms.Controls.DreaminePasswordBox.PasswordChanged
EventHandler? PasswordChanged
Definition
DreaminePasswordBox.cs:175
Dreamine.UI.WinForms.Controls.DreaminePasswordBox.Hint
string Hint
Definition
DreaminePasswordBox.cs:129
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.DreamineTheme
Definition
DreamineTheme.cs:14
Dreamine.UI.WinForms.DreamineTheme.CornerRadiusSmall
const int CornerRadiusSmall
Definition
DreamineTheme.cs:225
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.InputBackground
static readonly Color InputBackground
Definition
DreamineTheme.cs:42
Controls
DreaminePasswordBox.cs
다음에 의해 생성됨 :
1.17.0