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 pathBaseFileInput.vb
More file actions
269 lines (251 loc) · 9.46 KB
/
Copy pathBaseFileInput.vb
File metadata and controls
269 lines (251 loc) · 9.46 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
Imports System.Drawing.Drawing2D
Imports System.IO
Public Class BaseFileInput
Inherits Transparent.Panel
Private color As Color = Globals.Palette("Secondary")
Public FilePath As String = ""
Public Sub New()
Me.BackColor = Globals.Palette("Plain Light")
Me.BorderStyle = BorderStyle.None
Me.AutoSize = True
Me.MaximumSize = New Size(Globals.Unit(7), Globals.Unit(3))
Me.MinimumSize = New Size(Globals.Unit(7), Globals.Unit(3))
Dim Icon As New PictureBox With {
.Size = New Size(Globals.Unit(1), Globals.Unit(1)),
.Image = Globals.LoadSvgFromResource("File Input Icon", New Size(Globals.Unit(1), Globals.Unit(1))).Draw(),
.SizeMode = PictureBoxSizeMode.Zoom,
.Name = "Icon"
}
Icon.Location = New Point((Me.Width - Icon.Width) / 0.5, Globals.Unit(0.75))
Me.Controls.Add(Icon)
Dim Label As New Label With {
.Text = "Click to upload a .csv file.",
.Font = Globals.GetFont("Open Sans", Globals.Unit(0.5), FontStyle.Bold),
.ForeColor = color,
.AutoSize = True,
.Name = "Label",
.TextAlign = ContentAlignment.MiddleCenter
}
Label.Location = New Point((Me.Width - Label.Width) / 2, Globals.Unit(2))
Me.Controls.Add(Label)
For Each Control As Control In Me.Controls
AddHandler Control.MouseEnter, AddressOf BaseFileInput_MouseEnter
AddHandler Control.MouseLeave, AddressOf BaseFileInput_MouseLeave
AddHandler Control.Click, AddressOf BaseFileInput_Click
Next
End Sub
Protected Sub BaseFileInput_Resize(sender As Object, e As EventArgs) Handles Me.Resize
For Each Control As Control In Me.Controls
Control.Location = New Point((Me.Width - Control.Width) / 2, Control.Location.Y)
Next
End Sub
Protected Sub BaseFileInput_MouseEnter(sender As Object, e As EventArgs) Handles Me.MouseEnter
color = Globals.Palette("Plain Dark")
Dim Icon As PictureBox = Me.Controls("Icon")
Icon.Image = Globals.LoadSvgFromResource("File Input Icon Hovered", New Size(Globals.Unit(1), Globals.Unit(1))).Draw()
For Each Control As Control In Me.Controls
Control.ForeColor = color
Next
Me.Refresh()
End Sub
Protected Sub BaseFileInput_MouseLeave(sender As Object, e As EventArgs) Handles Me.MouseLeave
color = Globals.Palette("Secondary")
Dim Icon As PictureBox = Me.Controls("Icon")
Icon.Image = Globals.LoadSvgFromResource("File Input Icon", New Size(Globals.Unit(1), Globals.Unit(1))).Draw()
For Each Control As Control In Me.Controls
Control.ForeColor = color
Next
Me.Refresh()
End Sub
Protected Overrides Sub OnPaint(e As PaintEventArgs)
MyBase.OnPaint(e)
Dim g As Graphics = e.Graphics
Dim Pen As New Pen(color, Globals.Unit(0.1))
'TopLeft
g.DrawArc(
Pen,
Pen.Width / 2,
Pen.Width / 2,
CInt(Globals.Unit(0.5)),
CInt(Globals.Unit(0.5)),
180,
90
)
'Left
g.DrawLine(
Pen,
Pen.Width / 2,
CInt(Pen.Width / 2 + Globals.Unit(0.25)),
Pen.Width / 2,
CInt(Me.Height - Pen.Width / 2 - Globals.Unit(0.25))
)
'BottomLeft
g.DrawArc(
Pen,
Pen.Width / 2,
CInt(Me.Height - Globals.Unit(0.5) - Pen.Width),
CInt(Globals.Unit(0.5)),
CInt(Globals.Unit(0.5)),
90,
90
)
'Bottom
g.DrawLine(
Pen,
CInt(Pen.Width / 2 + Globals.Unit(0.25)),
CInt(Me.Height - Pen.Width / 2),
CInt(Me.Width - Pen.Width / 2 - Globals.Unit(0.25)),
CInt(Me.Height - Pen.Width / 2)
)
'BottomRight
g.DrawArc(
Pen,
CInt(Me.Width - Globals.Unit(0.5) - Pen.Width),
CInt(Me.Height - Globals.Unit(0.5) - Pen.Width),
CInt(Globals.Unit(0.5)),
CInt(Globals.Unit(0.5)),
0,
90
)
'Right
g.DrawLine(
Pen,
CInt(Me.Width - Pen.Width / 2),
CInt(Me.Height - Globals.Unit(0.25) - Pen.Width / 2),
CInt(Me.Width - Pen.Width / 2),
CInt(Pen.Width / 2 + Globals.Unit(0.25))
)
'TopRight
g.DrawArc(
Pen,
CInt(Me.Width - Globals.Unit(0.5) - Pen.Width),
Pen.Width / 2,
CInt(Globals.Unit(0.5)),
CInt(Globals.Unit(0.5)),
270,
90
)
'Top
g.DrawLine(
Pen,
CInt(Me.Width - Globals.Unit(0.25)),
Pen.Width / 2,
CInt(Pen.Width / 2 + Globals.Unit(0.25)),
Pen.Width / 2
)
Dim Path As New GraphicsPath
Path.AddArc(
0,
0,
CInt(Globals.Unit(0.5)),
CInt(Globals.Unit(0.5)),
180,
90
)
Path.AddLine(
0,
CInt(Globals.Unit(0.25)),
0,
CInt(Me.Height - Globals.Unit(0.25))
)
Path.AddArc(
0,
CInt(Me.Height - Globals.Unit(0.5)),
CInt(Globals.Unit(0.5)),
CInt(Globals.Unit(0.5)),
90,
90
)
Path.AddLine(
CInt(Globals.Unit(0.25)),
Me.Height,
CInt(Me.Width - Globals.Unit(0.25)),
Me.Height
)
Path.AddArc(
CInt(Me.Width - Globals.Unit(0.5)),
Me.Height - CInt(Globals.Unit(0.5)),
CInt(Globals.Unit(0.5)),
CInt(Globals.Unit(0.5)),
0,
90
)
Path.AddLine(
Me.Width,
CInt(Me.Height - Globals.Unit(0.25)),
Me.Width,
CInt(Globals.Unit(0.25))
)
Path.AddArc(
CInt(Me.Width - Globals.Unit(0.5)),
0,
CInt(Globals.Unit(0.5)),
CInt(Globals.Unit(0.5)),
270,
90
)
Path.AddLine(
CInt(Me.Width - Globals.Unit(0.25)),
0,
CInt(Globals.Unit(0.25)),
0
)
Me.Region = New Region(Path)
End Sub
Protected Sub BaseFileInput_Click(sender As Object, e As EventArgs) Handles Me.Click
Dim Dialog As New OpenFileDialog With {
.Filter = "CSV Files (*.csv)|*.csv",
.Title = "Select a CSV File"
}
If Dialog.ShowDialog() = DialogResult.OK Then
Dim Label As Label = Me.Controls("Label")
Label.Text = Path.GetFileName(Dialog.FileName)
Me.FilePath = Dialog.FileName
RaiseEvent FileSelected(Me, New EventArgs)
BaseFileInput_Resize(Me, New EventArgs)
End If
End Sub
Public Event FileSelected(sender As Object, e As EventArgs)
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.color = Globals.Palette("Secondary")
Dim Label As Label = Me.Controls("Label")
Label.ForeColor = Me.color
Dim Icon As PictureBox = Me.Controls("Icon")
Icon.Image = Globals.LoadSvgFromResource("File Input Icon", New Size(Globals.Unit(1), Globals.Unit(1))).Draw()
Alerted = False
Else
Me.color = Globals.Palette("Primary Compliment")
Dim Label As Label = Me.Controls("Label")
Label.ForeColor = Me.color
Dim Icon As PictureBox = Me.Controls("Icon")
Icon.Image = Globals.LoadSvgFromResource("File Input Icon Alerted", New Size(Globals.Unit(1), Globals.Unit(1))).Draw()
Alerted = True
End If
Me.Refresh()
End Sub
Timer.Start()
Me.TimerToStop = New Timer With {
.Interval = Globals.Unit(50)
}
AddHandler TimerToStop.Tick, Sub()
Timer.Stop()
TimerToStop.Stop()
Me.color = Globals.Palette("Secondary")
Dim Label As Label = Me.Controls("Label")
Label.ForeColor = Me.color
Dim Icon As PictureBox = Me.Controls("Icon")
Icon.Image = Globals.LoadSvgFromResource("File Input Icon", New Size(Globals.Unit(1), Globals.Unit(1))).Draw()
Me.Refresh()
End Sub
TimerToStop.Start()
My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Asterisk)
End Sub
End Class