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 pathBaseModal.vb
More file actions
292 lines (256 loc) · 12 KB
/
Copy pathBaseModal.vb
File metadata and controls
292 lines (256 loc) · 12 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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
Imports System.Reflection
Imports System.Resources
Public Class BaseModal
Inherits Form
Property Title As String
Property Message As String
Property Buttons As Dictionary(Of String, DialogResult)
Private Timer As Timer
Private TimerToStop As Timer
Public Sub New()
If Buttons Is Nothing Then
Buttons = New Dictionary(Of String, DialogResult) From {
{"OK", DialogResult.OK}
}
End If
If Buttons.Count > 2 Then
Throw New Exception("Only 2 buttons are allowed")
End If
End Sub
Protected Sub BaseModal_Load(sender As Object, e As EventArgs) Handles Me.Load
Me.BackColor = Globals.Palette("White")
Me.ForeColor = Globals.Palette("Secondary")
Me.Size = New Size(Globals.Unit(15), Globals.Unit(10))
Me.Location = New Point(
(Screen.PrimaryScreen.WorkingArea.Width - Me.Width) / 2,
(Screen.PrimaryScreen.WorkingArea.Height - Me.Height) / 2
)
Me.FormBorderStyle = FormBorderStyle.None
Me.ControlBox = False
Me.Icon = My.Resources.ResourceManager.GetObject("Icon")
Me.ShowInTaskbar = True
My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Asterisk)
Dim Highlighted As Boolean = False
Dim HeaderBar As New Panel With {
.Size = New Size(Me.Width, Globals.Unit(1)),
.Dock = DockStyle.Top,
.BackColor = Me.ForeColor
}
Me.Controls.Add(HeaderBar)
Dim TitleLabel As New Label With {
.Text = Me.Title,
.Font = Globals.GetFont("Raleway", Globals.Unit(0.5), FontStyle.Bold),
.ForeColor = Me.BackColor,
.Size = New Size(
HeaderBar.Width - Globals.Unit(4),
HeaderBar.Height
),
.AutoSize = False,
.TextAlign = ContentAlignment.MiddleCenter
}
TitleLabel.Location = New Point(
(HeaderBar.Width - TitleLabel.Width) / 2,
(HeaderBar.Height - TitleLabel.Height) / 2
)
HeaderBar.Controls.Add(TitleLabel)
Dim Logo As New PictureBox With {
.SizeMode = PictureBoxSizeMode.Zoom,
.Name = "Logo",
.Size = New Size(Globals.Unit(0.75), Globals.Unit(0.75)),
.Location = New Point(Globals.Unit(1.125), Globals.Unit(0.125))
}
Dim resourcesManager As ResourceManager = My.Resources.ResourceManager
Dim LogoImage As Image = resourcesManager.GetObject("Logo")
Logo.Image = LogoImage
HeaderBar.Controls.Add(Logo)
Dim CloseButton As New PictureBox With {
.Name = "CloseButton",
.Size = New Size(Globals.Unit(1), Globals.Unit(1)),
.SizeMode = PictureBoxSizeMode.CenterImage,
.Padding = New Padding(0),
.Margin = New Padding(0),
.Image = Globals.LoadSvgFromResource("Close Window", New Size(Globals.Unit(1), Globals.Unit(1))).Draw(),
.Location = New Point(HeaderBar.Width - Globals.Unit(2), 0)
}
AddHandler CloseButton.MouseEnter, Sub()
Try
CloseButton.BackColor = Color.FromArgb(
Me.ForeColor.R + Globals.Unit(1),
Me.ForeColor.G + Globals.Unit(1),
Me.ForeColor.B + Globals.Unit(1)
)
Catch ex As Exception
End Try
End Sub
AddHandler CloseButton.MouseLeave, Sub()
CloseButton.BackColor = Me.ForeColor
End Sub
AddHandler CloseButton.Click, Sub()
Me.DialogResult = DialogResult.Cancel
End Sub
HeaderBar.Controls.Add(CloseButton)
For Each Control As Control In New List(Of Control) From {HeaderBar, TitleLabel, Logo, CloseButton}
Control.Cursor = Cursors.SizeAll
AddHandler Control.MouseDown, AddressOf HeaderBar_MouseDown
AddHandler Control.MouseMove, AddressOf HeaderBar_MouseMove
AddHandler Control.MouseUp, AddressOf HeaderBar_MouseUp
Next
Dim MessageLabelPanel As New Panel With {
.Size = New Size(
Me.Width - Globals.Unit(2),
Globals.Unit(3)
),
.AutoScroll = True
}
MessageLabelPanel.Location = New Point(
(Me.Width - MessageLabelPanel.Width) / 2,
HeaderBar.Height + Globals.Unit(1)
)
Me.Controls.Add(MessageLabelPanel)
Dim MessageLabel As New Label With {
.Text = Me.Message,
.Font = Globals.GetFont("Open Sans", Globals.Unit(0.5), FontStyle.Regular),
.ForeColor = Globals.Palette("Plain Dark"),
.MinimumSize = New Size(Me.Width - Globals.Unit(2) - (SystemInformation.VerticalScrollBarWidth * 2), 0),
.MaximumSize = New Size(Me.Width - Globals.Unit(2) - (SystemInformation.VerticalScrollBarWidth * 2), 0),
.AutoSize = True,
.TextAlign = ContentAlignment.MiddleCenter,
.Location = New Point(SystemInformation.VerticalScrollBarWidth, 0)
}
MessageLabelPanel.Controls.Add(MessageLabel)
Dim ButtonPanel As New Panel With {
.Size = New Size(Me.Width - Globals.Unit(2), Globals.Unit(1))
}
ButtonPanel.Location = New Point(
(Me.Width - ButtonPanel.Width) / 2,
MessageLabelPanel.Bottom + Globals.Unit(1)
)
Me.Controls.Add(ButtonPanel)
Dim Button1 As New BaseButton With {
.Text = Buttons.Keys(0),
.Name = Buttons.Keys(0),
.Size = New Size(Globals.Unit(5), Globals.Unit(1)),
.Location = New Point(
(ButtonPanel.Width - Globals.Unit(5)) / 2,
0
)
}
AddHandler Button1.Click, Sub()
Me.DialogResult = Buttons.Values(0)
End Sub
ButtonPanel.Controls.Add(Button1)
Dim Button2 As BaseButton
If Buttons.Count = 2 Then
Button2 = New BaseButton With {
.Text = Buttons.Keys(1),
.Name = Buttons.Keys(1),
.Size = New Size(Globals.Unit(5), Globals.Unit(1))
}
AddHandler Button2.Click, Sub()
Me.DialogResult = Buttons.Values(1)
End Sub
ButtonPanel.Controls.Add(Button2)
Button1.Location = New Point(0, 0)
Button2.Location = New Point(ButtonPanel.Width - Button2.Width, 0)
End If
Dim BorderLeft As New Panel With {
.Size = New Size(Globals.Unit(0.1), Me.Height),
.Location = New Point(0, 0),
.BackColor = Me.ForeColor
}
Me.Controls.Add(BorderLeft)
Dim BorderRight As New Panel With {
.Size = New Size(Globals.Unit(0.1), Me.Height),
.Location = New Point(Me.Width - Globals.Unit(0.1), 0),
.BackColor = Me.ForeColor
}
Me.Controls.Add(BorderRight)
Dim BorderBottom As New Panel With {
.Size = New Size(Me.Width, Globals.Unit(0.1)),
.Location = New Point(0, Me.Height - Globals.Unit(0.1)),
.BackColor = Me.ForeColor
}
Me.Controls.Add(BorderBottom)
Me.Timer = New Timer With {
.Interval = Globals.Unit(3)
}
AddHandler Timer.Tick, Sub()
If Highlighted Then
Me.ForeColor = Globals.Palette("Primary Compliment")
HeaderBar.BackColor = Globals.Palette("Primary Compliment")
Button1.BackColor = Globals.Palette("Primary Compliment")
If Buttons.Count = 2 Then
Button2.BackColor = Globals.Palette("Primary Compliment")
End If
BorderLeft.BackColor = Globals.Palette("Primary Compliment")
BorderRight.BackColor = Globals.Palette("Primary Compliment")
BorderBottom.BackColor = Globals.Palette("Primary Compliment")
Highlighted = False
Else
Me.ForeColor = Globals.Palette("Secondary")
HeaderBar.BackColor = Globals.Palette("Secondary")
Button1.BackColor = Globals.Palette("Secondary")
If Buttons.Count = 2 Then
Button2.BackColor = Globals.Palette("Secondary")
End If
BorderLeft.BackColor = Globals.Palette("Secondary")
BorderRight.BackColor = Globals.Palette("Secondary")
BorderBottom.BackColor = Globals.Palette("Secondary")
Highlighted = True
End If
End Sub
Timer.Start()
Me.TimerToStop = New Timer With {
.Interval = Globals.Unit(50)
}
AddHandler TimerToStop.Tick, Sub()
Timer.Stop()
Timer.Dispose()
TimerToStop.Stop()
TimerToStop.Dispose()
Me.ForeColor = Globals.Palette("Secondary")
HeaderBar.BackColor = Globals.Palette("Secondary")
BorderLeft.BackColor = Globals.Palette("Secondary")
BorderRight.BackColor = Globals.Palette("Secondary")
BorderBottom.BackColor = Globals.Palette("Secondary")
End Sub
TimerToStop.Start()
End Sub
Protected Is_HeaderBar_MouseDown As Boolean = False
Protected MouseLocationInsideTheForm As Point
Protected Sub HeaderBar_MouseDown(sender As Object, e As MouseEventArgs)
Is_HeaderBar_MouseDown = True
MouseLocationInsideTheForm = Me.PointToClient(Cursor.Position)
End Sub
Protected Sub HeaderBar_MouseMove(sender As Object, e As MouseEventArgs)
If Is_HeaderBar_MouseDown Then
If Me.WindowState = FormWindowState.Maximized Then
Me.WindowState = FormWindowState.Normal
End If
Dim CursorLocation = Cursor.Position
Dim NewLocation As New Point(
CursorLocation.X - MouseLocationInsideTheForm.X,
CursorLocation.Y - MouseLocationInsideTheForm.Y
)
If NewLocation.X < 0 Then
NewLocation = New Point(
0,
NewLocation.Y
)
End If
If NewLocation.Y < 0 Then
NewLocation = New Point(
NewLocation.X,
0
)
End If
Me.Location = NewLocation
End If
End Sub
Protected Sub HeaderBar_MouseUp(sender As Object, e As MouseEventArgs)
Is_HeaderBar_MouseDown = False
If Me.Location.Y = 0 Then
Me.WindowState = FormWindowState.Maximized
End If
End Sub
End Class