-
Notifications
You must be signed in to change notification settings - Fork 3
/
dialogMultiChoice.vb
386 lines (386 loc) · 16.5 KB
/
dialogMultiChoice.vb
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
Imports System.Windows.Forms
Public Class dialogMultiChoice
''' <summary>
''' PdForms.net - An open source pdf form editor
''' Copyright 2018 NK-INC.COM All Rights reserved.
''' PdForms.net utilizes iTextSharp technologies.
''' Website: www.pdforms.net (source code), www.pdforms.com (about)
''' </summary>
Dim frm As frmMain = Nothing
Public Sub New(ByRef ownerFrmMain As System.Windows.Forms.IWin32Window)
InitializeComponent()
If Not Me.Owner Is Nothing Then
If Me.Owner.GetType Is GetType(frmMain) Then
frm = DirectCast(Me.Owner, frmMain)
End If
End If
Me.DialogResult = Windows.Forms.DialogResult.None
End Sub
Public Sub New()
InitializeComponent()
Me.DialogResult = Windows.Forms.DialogResult.None
End Sub
Public DefaultButtonIndex As Integer = 0
Public dialogResult1 As Integer = Windows.Forms.DialogResult.Yes
Public dialogResult2 As Integer = Windows.Forms.DialogResult.No
Public dialogResult3 As Integer = Windows.Forms.DialogResult.Cancel
Public dialogResult4 As Integer = Windows.Forms.DialogResult.Abort
Public Class clsButton
Public buttonText As String = ""
Public buttonVisible As Boolean = False
Public buttonResult As Integer = -1
Public Sub New(ByVal buttonText1 As String, ByVal buttonVisible1 As Boolean, ByVal buttonResult1 As Integer)
buttonText = buttonText1
buttonVisible = buttonVisible1
buttonResult = buttonResult1
End Sub
Public Function add(ByRef lstClsButton As List(Of clsButton), ByVal buttonText As String, ByVal buttonVisible As Boolean, ByVal buttonResult As Integer) As List(Of clsButton)
lstClsButton.Add(New clsButton(buttonText, buttonVisible, buttonResult))
Return lstClsButton
End Function
End Class
Public buttons As New List(Of clsButton)
Public Sub ButtonAdd(ByVal buttonText As String, ByVal buttonVisible As Boolean, ByVal buttonResult As Integer)
buttons.Add(New clsButton(buttonText, buttonVisible, buttonResult))
End Sub
Public Sub ButtonsClear()
If buttons Is Nothing Then
buttons = New List(Of clsButton)
ElseIf buttons.Count > 0 Then
buttons.Clear()
End If
End Sub
Public Function ButtonsArray() As clsButton()
If buttons Is Nothing Then
buttons = New List(Of clsButton)
End If
Return buttons.ToArray
End Function
Public Overloads Function ShowDialog(ByRef meOwner As frmMain, ByVal message As String, ByVal title As String, ByVal buttonClasses() As clsButton) As DialogResult
Me.Owner = meOwner
Me.lblMessage.Text = message & ""
Me.Text = title & ""
Try
Button1.Text = ""
Button1.Visible = False
dialogResult1 = -1
Button2.Text = ""
Button2.Visible = False
dialogResult2 = -1
Button3.Text = ""
Button3.Visible = False
dialogResult3 = -1
Button4.Text = ""
Button4.Visible = False
dialogResult4 = -1
If buttonClasses.Count > 0 Then
Button1.Text = buttonClasses(0).buttonText
Button1.Visible = buttonClasses(0).buttonVisible
dialogResult1 = buttonClasses(0).buttonResult
If buttonClasses.Count > 1 Then
Button2.Text = buttonClasses(1).buttonText
Button2.Visible = buttonClasses(1).buttonVisible
dialogResult2 = buttonClasses(1).buttonResult
If buttonClasses.Count > 2 Then
Button3.Text = buttonClasses(2).buttonText
Button3.Visible = buttonClasses(2).buttonVisible
dialogResult3 = buttonClasses(2).buttonResult
If buttonClasses.Count > 3 Then
Button4.Text = buttonClasses(3).buttonText
Button4.Visible = buttonClasses(3).buttonVisible
dialogResult4 = buttonClasses(3).buttonResult
End If
End If
End If
End If
Select Case DefaultButtonIndex
Case 0
AcceptButton = Button1
Case 1
AcceptButton = Button2
Case 2
AcceptButton = Button3
Case 3
AcceptButton = Button4
Case Else
AcceptButton = Button1
End Select
If Not Me.Owner Is Nothing Then
If Me.Owner.GetType Is GetType(frmMain) Then
frm = DirectCast(Me.Owner, frmMain)
Return Me.ShowDialog(Me.Owner)
End If
End If
Return Me.DialogResult
Catch ex As Exception
Err.Clear()
Finally
Me.Close()
End Try
End Function
Public Overloads Function ShowDialog(ByRef meOwner As frmMain, ByVal title As String, ByVal buttonClasses() As clsButton) As DialogResult
Me.Owner = meOwner
Me.Text = title & ""
Try
Button1.Text = ""
Button1.Visible = False
dialogResult1 = -1
Button2.Text = ""
Button2.Visible = False
dialogResult2 = -1
Button3.Text = ""
Button3.Visible = False
dialogResult3 = -1
Button4.Text = ""
Button4.Visible = False
dialogResult4 = -1
If buttonClasses.Count > 0 Then
Button1.Text = buttonClasses(0).buttonText
Button1.Visible = buttonClasses(0).buttonVisible
dialogResult1 = buttonClasses(0).buttonResult
If buttonClasses.Count > 1 Then
Button2.Text = buttonClasses(1).buttonText
Button2.Visible = buttonClasses(1).buttonVisible
dialogResult2 = buttonClasses(1).buttonResult
If buttonClasses.Count > 2 Then
Button3.Text = buttonClasses(2).buttonText
Button3.Visible = buttonClasses(2).buttonVisible
dialogResult3 = buttonClasses(2).buttonResult
If buttonClasses.Count > 3 Then
Button4.Text = buttonClasses(3).buttonText
Button4.Visible = buttonClasses(3).buttonVisible
dialogResult4 = buttonClasses(3).buttonResult
End If
End If
End If
End If
Select Case DefaultButtonIndex
Case 0
AcceptButton = Button1
Case 1
AcceptButton = Button2
Case 2
AcceptButton = Button3
Case 3
AcceptButton = Button4
Case Else
AcceptButton = Button1
End Select
If Not Me.Owner Is Nothing Then
If Me.Owner.GetType Is GetType(frmMain) Then
frm = DirectCast(Me.Owner, frmMain)
Return Me.ShowDialog(Me.Owner)
End If
End If
Return Me.DialogResult
Catch ex As Exception
Err.Clear()
Finally
Me.Close()
End Try
End Function
Public Overloads Function ShowDialog(ByVal message As String, ByVal title As String, ByVal buttonText() As String, ByVal buttonVisible() As Boolean, ByVal buttonResults() As Integer) As DialogResult
Me.lblMessage.Text = message & ""
Me.Text = title & ""
Try
Button1.Text = ""
Button1.Visible = False
dialogResult1 = -1
Button2.Text = ""
Button2.Visible = False
dialogResult2 = -1
Button3.Text = ""
Button3.Visible = False
dialogResult3 = -1
Button4.Text = ""
Button4.Visible = False
dialogResult4 = -1
If buttonText.Length > 0 Then
Button1.Text = buttonText(0)
Button1.Visible = buttonVisible(0)
dialogResult1 = buttonResults(0)
If buttonText.Length > 1 Then
Button2.Text = buttonText(1)
Button2.Visible = buttonVisible(1)
dialogResult2 = buttonResults(1)
If buttonText.Length > 2 Then
Button3.Text = buttonText(2)
Button3.Visible = buttonVisible(2)
dialogResult3 = buttonResults(2)
If buttonText.Length > 3 Then
Button4.Text = buttonText(3)
Button4.Visible = buttonVisible(3)
dialogResult4 = buttonResults(3)
End If
End If
End If
End If
Select Case DefaultButtonIndex
Case 0
AcceptButton = Button1
Case 1
AcceptButton = Button2
Case 2
AcceptButton = Button3
Case 3
AcceptButton = Button4
Case Else
AcceptButton = Button1
End Select
If Not Me.Owner Is Nothing Then
If Me.Owner.GetType Is GetType(frmMain) Then
frm = DirectCast(Me.Owner, frmMain)
Return Me.ShowDialog(Me.Owner)
End If
End If
Return Me.DialogResult
Catch ex As Exception
Err.Clear()
Finally
Me.Close()
End Try
End Function
Public Overloads Function ShowDialog(ByVal message As String, ByVal MsgBoxStyleInt As Integer, ByVal title As String) As DialogResult
Me.lblMessage.Text = message & ""
Me.Text = title & ""
Try
If (MsgBoxStyleInt + MsgBoxStyle.YesNo) > 0 Then
Button1.Text = "YES"
Button2.Text = "No"
Button3.Text = "Cancel"
Button4.Text = "Don't Ask"
Button1.Visible = True
Button2.Visible = True
Button3.Visible = False
Button4.Visible = False
dialogResult1 = Windows.Forms.DialogResult.Yes
dialogResult2 = Windows.Forms.DialogResult.No
dialogResult3 = Windows.Forms.DialogResult.Cancel
dialogResult4 = Windows.Forms.DialogResult.Abort
ElseIf (MsgBoxStyleInt + MsgBoxStyle.YesNoCancel) > 0 Then
Button1.Text = "YES"
Button2.Text = "No"
Button3.Text = "Cancel"
Button4.Text = "Don't Ask"
Button1.Visible = True
Button2.Visible = True
Button4.Visible = True
Button3.Visible = False
dialogResult1 = Windows.Forms.DialogResult.Yes
dialogResult2 = Windows.Forms.DialogResult.No
dialogResult3 = Windows.Forms.DialogResult.Cancel
dialogResult4 = Windows.Forms.DialogResult.Abort
ElseIf (MsgBoxStyleInt + MsgBoxStyle.OkOnly) > 0 Then
Button1.Text = "Ok"
Button2.Text = "No"
Button3.Text = "Cancel"
Button4.Text = "Don't Ask"
Button1.Visible = True
Button2.Visible = False
Button4.Visible = False
Button3.Visible = False
dialogResult1 = Windows.Forms.DialogResult.OK
dialogResult2 = Windows.Forms.DialogResult.No
dialogResult3 = Windows.Forms.DialogResult.Cancel
dialogResult4 = Windows.Forms.DialogResult.Abort
ElseIf (MsgBoxStyleInt + MsgBoxStyle.OkCancel) > 0 Then
Button1.Text = "Ok"
Button2.Text = "No"
Button3.Text = "Cancel"
Button4.Text = "Don't Ask"
Button1.Visible = True
Button2.Visible = False
Button3.Visible = True
Button4.Visible = False
dialogResult1 = Windows.Forms.DialogResult.OK
dialogResult2 = Windows.Forms.DialogResult.No
dialogResult3 = Windows.Forms.DialogResult.Cancel
dialogResult4 = Windows.Forms.DialogResult.Abort
ElseIf (MsgBoxStyleInt + MsgBoxStyle.AbortRetryIgnore) > 0 Then
Button1.Text = "Ok"
Button2.Text = "Ignore"
Button3.Text = "Retry"
Button4.Text = "Abort"
Button1.Visible = False
Button2.Visible = True
Button3.Visible = True
Button4.Visible = True
dialogResult1 = Windows.Forms.DialogResult.OK
dialogResult2 = Windows.Forms.DialogResult.Ignore
dialogResult3 = Windows.Forms.DialogResult.Retry
dialogResult4 = Windows.Forms.DialogResult.Abort
Else
Button1.Text = "YES"
Button2.Text = "No"
Button3.Text = "Cancel"
Button4.Text = "Yes,Don't ask"
Button1.Visible = True
Button2.Visible = True
Button4.Visible = True
Button3.Visible = True
dialogResult1 = Windows.Forms.DialogResult.Yes
dialogResult2 = Windows.Forms.DialogResult.No
dialogResult3 = Windows.Forms.DialogResult.Cancel
dialogResult4 = Windows.Forms.DialogResult.Abort
End If
Select Case DefaultButtonIndex
Case 0
AcceptButton = Button1
Case 1
AcceptButton = Button2
Case 2
AcceptButton = Button3
Case 3
AcceptButton = Button4
Case Else
AcceptButton = Button1
End Select
If Not Me.Owner Is Nothing Then
If Me.Owner.GetType Is GetType(frmMain) Then
frm = DirectCast(Me.Owner, frmMain)
Return Me.ShowDialog(Me.Owner)
End If
End If
Return Me.DialogResult
Catch ex As Exception
Err.Clear()
Finally
Me.Close()
End Try
End Function
Dim blnSelected As Boolean = False
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.DialogResult = DirectCast(dialogResult1, DialogResult)
If frm.GetType Is GetType(frmMain) And Not frm Is Nothing Then
blnSelected = True
Else
blnSelected = True
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.DialogResult = DirectCast(dialogResult2, DialogResult)
If frm.GetType Is GetType(frmMain) And Not frm Is Nothing Then
blnSelected = True
Else
blnSelected = True
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.DialogResult = DirectCast(dialogResult3, DialogResult)
If frm.GetType Is GetType(frmMain) And Not frm Is Nothing Then
blnSelected = True
Else
blnSelected = True
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.DialogResult = DirectCast(dialogResult4, DialogResult)
If frm.GetType Is GetType(frmMain) And Not frm Is Nothing Then
blnSelected = True
Else
blnSelected = True
End If
End Sub
Private Sub dialogMultiChoice_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class