This repository was archived by the owner on Jun 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseTextInput.vb
More file actions
136 lines (117 loc) · 5.25 KB
/
Copy pathBaseTextInput.vb
File metadata and controls
136 lines (117 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
Public Class BaseTextInput
Inherits Control
Private Label As New Transparent.Label
Private TextBox As New Transparent.TextBox
Private ReadOnly Underline As New Panel
Overloads Property Name As String
Get
Return Me.Label.Text
End Get
Set(value As String)
Me.Label.Text = value
End Set
End Property
Overloads Property Text As String
Get
Return Me.TextBox.Text
End Get
Set(value As String)
Me.TextBox.Text = value
End Set
End Property
Overloads Property PasswordChar As Char
Get
Return Me.TextBox.PasswordChar
End Get
Set(value As Char)
Me.TextBox.PasswordChar = value
End Set
End Property
Public Sub New()
SetStyle(ControlStyles.SupportsTransparentBackColor, True)
Me.BackColor = Color.Transparent
Me.Controls.Add(Me.Label)
Me.Controls.Add(Me.TextBox)
Me.Controls.Add(Me.Underline)
If Me.Size = New Size(0, 0) Then
Me.Size = New Size(Globals.Unit(10), Globals.Unit(1))
End If
Me.Label.Location = New Point(Globals.Unit(0.25), Globals.Unit(0.25))
Me.Label.Size = New Size(Me.Width - Globals.Unit(0.5), Globals.Unit(0.5))
Me.Label.AutoSize = False
Me.Label.Font = Globals.GetFont("Raleway", Globals.Unit(0.5), FontStyle.Bold)
Me.Label.ForeColor = Globals.Palette("Plain Dark")
Me.Label.BackColor = Color.Transparent
Me.Label.TextAlign = ContentAlignment.MiddleLeft
AddHandler Me.Label.Click, AddressOf FocusTextBox
Me.TextBox.Location = New Point(Globals.Unit(0.25), Globals.Unit(0.25))
Me.TextBox.Size = New Size(Me.Width - Globals.Unit(0.5), Me.Height - Globals.Unit(0.25))
Me.TextBox.AutoSize = False
Me.TextBox.Font = Globals.GetFont("Open Sans", Globals.Unit(0.5), FontStyle.Regular)
Me.TextBox.ForeColor = Globals.Palette("Plain Dark")
Me.TextBox.BorderStyle = BorderStyle.None
Me.TextBox.TextAlign = HorizontalAlignment.Left
AddHandler Me.TextBox.GotFocus, AddressOf FocusTextBox
AddHandler Me.TextBox.LostFocus, AddressOf UnfocusTextBox
Me.Underline.Location = New Point(0, Me.Height - Globals.Unit(0.05))
Me.Underline.Size = New Size(Me.Width, Globals.Unit(0.05))
Me.Underline.BackColor = Globals.Palette("Plain Dark")
Me.Underline.BringToFront()
AddHandler Me.GotFocus, Sub()
Me.TextBox.Focus()
End Sub
End Sub
Private Sub FocusTextBox(sender As Object, e As EventArgs)
Me.Label.Location = New Point(Globals.Unit(0.125), 0)
Me.Label.Size = New Size(Me.Width - Globals.Unit(0.25), Globals.Unit(0.25))
Me.Label.Font = Globals.GetFont("Raleway", Globals.Unit(0.25), FontStyle.Bold)
Me.BackColor = Globals.Palette("White")
Me.Label.ForeColor = Globals.Palette("Secondary")
Me.Underline.BackColor = Globals.Palette("Secondary")
Me.TextBox.Focus()
End Sub
Private Sub UnfocusTextBox(sender As Object, e As EventArgs)
If Me.TextBox.Text = "" Then
Me.Label.Location = New Point(Globals.Unit(0.25), Globals.Unit(0.25))
Me.Label.Size = New Size(Me.Width - Globals.Unit(0.5), Globals.Unit(0.5))
Me.Label.Font = Globals.GetFont("Raleway", Globals.Unit(0.5), FontStyle.Bold)
Me.BackColor = Color.Transparent
End If
Me.Label.ForeColor = Globals.Palette("Plain Dark")
Me.Underline.BackColor = Globals.Palette("Plain Dark")
End Sub
Protected Sub BaseTextInput_Resize(sender As Object, e As EventArgs) Handles Me.Resize
Me.Label.Size = New Size(Me.Width - Globals.Unit(0.5), Globals.Unit(0.5))
Me.TextBox.Size = New Size(Me.Width - Globals.Unit(0.5), Me.Height - Globals.Unit(0.25))
Me.Underline.Size = New Size(Me.Width, Globals.Unit(0.05))
End Sub
Private Timer As Timer
Private TimerToStop As Timer
Public Sub Alert()
Dim Alerted As Boolean = False
Me.Timer = New Timer With {
.Interval = Globals.Unit(3)
}
AddHandler Timer.Tick, Sub()
If Alerted Then
Me.Underline.BackColor = Globals.Palette("Secondary")
Alerted = False
Else
Me.Underline.BackColor = Globals.Palette("Primary Compliment")
Alerted = True
End If
End Sub
Timer.Start()
Me.TimerToStop = New Timer With {
.Interval = Globals.Unit(50)
}
AddHandler TimerToStop.Tick, Sub()
Timer.Stop()
TimerToStop.Stop()
Me.Underline.BackColor = Globals.Palette("Plain Dark")
End Sub
TimerToStop.Start()
Me.TextBox.Focus()
My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Asterisk)
End Sub
End Class