-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUFBasicMulti.frm
758 lines (644 loc) · 26.2 KB
/
UFBasicMulti.frm
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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} UFBasicMulti
Caption = "Information"
ClientHeight = 2.45040e5
ClientLeft = 5460
ClientTop = 5595
ClientWidth = 2.45475e5
OleObjectBlob = "UFBasicMulti.frx":0000
End
Attribute VB_Name = "UFBasicMulti"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'@Folder("Userform.GeneralForm")
'********************************************************
'This is the Generalized Userform for the used in different modules
'Arthor: Lucas LEUNG
'Update Log
'Aug 2023 - Initial
'*******************************************************
Option Explicit
'For Hiding Default Tilte Bar and using own title bar
Private Const WM_NCLBUTTONDOWN = &HA1&
Private Const HTCAPTION = 2&
'Private Const WS_BORDER = &H800000
Private Declare PtrSafe Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare PtrSafe Function GetWindowLong Lib "User32" Alias "GetWindowLongA" (ByVal HWND As Long, ByVal nIndex As Long) As Long
Private Declare PtrSafe Function SetWindowLongPtr Lib "User32" Alias "SetWindowLongA" (ByVal HWND As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare PtrSafe Function DrawMenuBar Lib "User32" (ByVal HWND As Long) As Long
Private Declare PtrSafe Sub ReleaseCapture Lib "User32" ()
Private Declare PtrSafe Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal HWND As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private gHWND As Long
Private Const GWL_STYLE As Long = (-16)
'For
Private mmupMain As msForms.MultiPage, mfra() As msForms.frame
Private mbIsButtonAtCenter As Boolean
Private mCurrentPage As Integer
Private eventHandlerCollection As New Collection
Private pHoriSpace As Long, pVertSpace As Long
Private cTopPos() As Double, pBotMargin As Double
Private pCloseMode As Integer '0 when OK button is pressed, -1 when cancel button is pressed
'******************************************************************************************
'***************************For Customized Title Bar***************************************
'******************************************************************************************
Private Sub HandleDragMove(HWND As Long)
Call ReleaseCapture
Call SendMessage(HWND, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End Sub
Private Sub LabelX_Click()
pCloseMode = -1
Me.Hide
End Sub
Private Sub MyTitleBar_Caption_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
If Button = 1 Then HandleDragMove gHWND
End Sub
'*****************************************************************************************************************
'***************************Button Hover Control/ OK Cancel Button Control****************************************
'*****************************************************************************************************************
Private Sub OKButtonInactive_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
'PURPOSE: Make OK Button appear Green when hovered on
CancelButtonInactive.Visible = True
OKButtonInactive.Visible = False
End Sub
Private Sub CancelButtonInactive_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
'PURPOSE: Make Cancel Button appear Green when hovered on
CancelButtonInactive.Visible = False
OKButtonInactive.Visible = True
End Sub
Private Sub Userform_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
'PURPOSE: Reset Userform buttons to Inactive Status
CancelButtonInactive.Visible = True
OKButtonInactive.Visible = True
End Sub
Private Sub CancelButton_Click()
pCloseMode = -1
Me.Hide
End Sub
Private Sub OKButton_Click()
pCloseMode = 0
Me.Hide
End Sub
'*****************************************************************************************************************
'***************************Initialization & Close Behaviour******************************************************
'*****************************************************************************************************************
Private Sub UserForm_Initialize()
'Remove default title bar and create own window
Dim frm As Long
Dim wHandle As Long
wHandle = FindWindow(vbNullString, Me.caption)
frm = GetWindowLong(wHandle, GWL_STYLE)
'frm = frm And WS_BORDER
SetWindowLongPtr wHandle, -16, 0
DrawMenuBar wHandle
gHWND = wHandle
'Other Initializetion
Me.height = 300
pHoriSpace = 10
pVertSpace = 10
pBotMargin = 10
'cTopPos(mCurrentPage) = 5
End Sub
Private Sub Userform_Activate()
MyTitleBar_Caption.width = Me.width
MyTitleBar_Border.width = Me.width
'Position t
Reposition_labelX
If mbIsButtonAtCenter Then
RepositionOkAndCancelButtonsToCenter
Else
RepositionOkAndCancelButtonsToRight
End If
Reposition_MultiPage
RepositionUF
End Sub
Public Sub Initialize(numPages As Integer, PageNames() As String, Optional width As Double = 300, _
Optional isButtonAtCenter As Boolean = True)
Dim i As Integer
CreateMultiPageObject numPages, PageNames
For i = 0 To numPages - 1
cTopPos(i) = 5
Next i
Me.width = width
mbIsButtonAtCenter = isButtonAtCenter
End Sub
Private Sub CreateMultiPageObject(numPages As Integer, PageNames() As String)
Dim i As Integer
Set mmupMain = Me.Controls.Add("Forms.MultiPage.1")
' With mmupMain
' .left = 0
' .top = 24
' .width = Me.width
' .height = Me.height - pBotMargin - 24 - pVertSpace - OKButton.height
' End With
ReDim mfra(0 To numPages - 1)
ReDim cTopPos(0 To numPages - 1)
If numPages > 2 Then
For i = 3 To numPages
mmupMain.Pages.Add , "Page " & i
Next i
End If
For i = 0 To numPages - 1
mmupMain.Pages(i).caption = PageNames(i)
mmupMain.value = i
Set mfra(i) = mmupMain.Pages.item(i).Controls.Add("Forms.Frame.1")
With mfra(i)
.BackColor = RGB(255, 255, 255) ' White background color
' .width = mmupMain.width
' .height = mmupMain.height
' .left = 0
' .top = 0
.BorderStyle = fmBorderStyleNone
End With
Next i
mmupMain.value = 0
End Sub
'*************************************************************************************************************************
'*************************************Basic Methods***********************************************************************
'*************************************************************************************************************************
Private Sub Reposition_labelX()
With LabelX
.top = 2
.left = Me.width - 20
End With
End Sub
Public Sub RepositionOkAndCancelButtonsToCenter()
With OKButton
.top = Me.height - pBotMargin - .height
.left = (Me.width / 2 - .width) / 2
End With
With OKButtonInactive
.top = Me.height - pBotMargin - .height
.left = (Me.width / 2 - .width) / 2
End With
With CancelButton
.top = Me.height - pBotMargin - .height
.left = Me.width / 2 + (Me.width / 2 - .width) / 2
End With
With CancelButtonInactive
.top = Me.height - pBotMargin - .height
.left = Me.width / 2 + (Me.width / 2 - .width) / 2
End With
End Sub
Public Sub RepositionOkAndCancelButtonsToRight()
With OKButton
.top = Me.height - pBotMargin - .height
.left = Me.width - pHoriSpace * 2 - .width * 2
End With
With OKButtonInactive
.top = Me.height - pBotMargin - .height
.left = Me.width - pHoriSpace * 2 - .width * 2
End With
With CancelButton
.top = Me.height - pBotMargin - .height
.left = Me.width - pHoriSpace - .width
End With
With CancelButtonInactive
.top = Me.height - pBotMargin - .height
.left = Me.width - pHoriSpace - .width
End With
'Debug.Print OKButton.top
End Sub
Private Sub Reposition_MultiPage()
Dim i As Integer
With mmupMain
.left = 0
.top = 24
.width = Me.width - 5
.height = Me.height - pBotMargin - 24 - pVertSpace - OKButton.height
End With
For i = 0 To UBound(mfra)
With mfra(i)
.width = mmupMain.width
.height = mmupMain.height
.left = 0
.top = 0
End With
Next i
End Sub
Private Sub RepositionUF()
Me.top = Application.top + (Application.UsableHeight / 2) - (Me.height / 2)
Me.left = Application.left + (Application.UsableWidth / 2) - (Me.width / 2)
End Sub
Property Get CurrentPage() As Integer
CurrentPage = mCurrentPage + 1
End Property
Property Let CurrentPage(num As Integer)
mCurrentPage = num - 1
End Property
Property Get CloseState() As Integer
CloseState = pCloseMode
End Property
Property Let TitleBarCaption(str As String)
MyTitleBar_Caption.caption = str
End Property
Property Get OKButtonActive() As Object
Set OKButtonActive = Me.OKButton
End Property
'*************************************************************************************************************************
'******************************Building UI Elements***********************************************************************
'*************************************************************************************************************************
'Public Function AddButton(ByRef reButton As MSForms.CommandButton, Optional caption As String = "Button", _
' Optional width As Double = 50, Optional height As Double = 15, _
' Optional top As Double = 10, Optional left As Double = 10, Optional pageNum As Integer = -1) As MSForms.CommandButton
' Dim btn As MSForms.CommandButton
'
' If pageNum = -1 Then
' Set btn = Me.Controls.Add("Forms.CommandButton.1")
' 'btn.zposition = front
' ElseIf pageNum = 0 Then 'ie: title bar of multipage userform
' Set btn = mmupMain.Pages.Item(0).Controls.Add("Forms.CommandButton.1")
' Else
' Set btn = mfra(pageNum).Controls.Add("Forms.CommandButton.1")
' End If
'
' With btn
' .height = height 'Application.Max(label.Height, 15)
' .width = width
' .top = top
' .left = left
' .caption = caption
' End With
'
' Set reButton = btn
'
'End Function
Public Function AddButton(Optional caption As String = "Button", _
Optional width As Double = 50, Optional height As Double = 15, _
Optional top As Double = 10, Optional left As Double = 10, Optional pageNum As Integer = -1) As msForms.CommandButton
Dim btn As msForms.CommandButton
If pageNum = -1 Then
Set btn = Me.Controls.Add("Forms.CommandButton.1")
'btn.zposition = front
ElseIf pageNum = 0 Then 'ie: title bar of multipage userform
Set btn = mmupMain.Pages.item(0).Controls.Add("Forms.CommandButton.1")
Else
Set btn = mfra(pageNum).Controls.Add("Forms.CommandButton.1")
End If
With btn
.height = height 'Application.Max(label.Height, 15)
.width = width
.top = top
.left = left
.caption = caption
End With
Set AddButton = btn
End Function
Public Sub AddCheckBox(reCheckbox As msForms.checkbox, Optional title As String = "Please Select", _
Optional Description As String, Optional isCheck As Boolean = False, Optional tipText As String, _
Optional labelWidth As Double)
Dim label As msForms.label
Dim checkbox As msForms.checkbox
If Not title = vbNullString Then
Set label = mfra(mCurrentPage).Controls.Add("Forms.Label.1")
With label
.top = cTopPos(mCurrentPage)
.left = pHoriSpace
.caption = title
If labelWidth = 0 Then
.width = (Me.width - pHoriSpace) / 2 - pHoriSpace
Else
.width = labelWidth
End If
.AutoSize = True
.ControlTipText = tipText
End With
End If
Set checkbox = mfra(mCurrentPage).Controls.Add("Forms.Checkbox.1")
With checkbox
.height = 15 'Application.Max(label.Height, 15)
.width = (Me.width - pHoriSpace) / 4
.top = cTopPos(mCurrentPage)
If labelWidth = 0 Then
.left = (Me.width - pHoriSpace) / 2 + pHoriSpace
Else
.left = labelWidth + pHoriSpace
End If
.value = isCheck
.caption = Description
End With
Set reCheckbox = checkbox
cTopPos(mCurrentPage) = cTopPos(mCurrentPage) + checkbox.height + 10
End Sub
Sub AddCheckBox_double(reCheckbox As msForms.checkbox, reCheckbox2 As msForms.checkbox, _
Optional title As String = "Please Select", Optional description1 As String, _
Optional description2 As String, Optional isCheck1 As Boolean = False, Optional isCheck2 As Boolean = False, _
Optional tipText As String)
Dim label As msForms.label, Label2 As msForms.label
Dim checkbox As msForms.checkbox, CheckBox2 As msForms.checkbox
AddCheckBox checkbox, title, description1, isCheck1, tipText
cTopPos(mCurrentPage) = cTopPos(mCurrentPage) - checkbox.height - 10
Set CheckBox2 = mfra(mCurrentPage).Controls.Add("Forms.Checkbox.1")
With CheckBox2
.height = 15 'Application.Max(label.Height, 15)
.width = (Me.width - pHoriSpace) / 4
.top = cTopPos(mCurrentPage)
.left = 3 * (Me.width - pHoriSpace) / 4 '(Me.Width - pHoriSpace) / 2 + pHoriSpace
.value = isCheck2
.caption = description2
End With
Set reCheckbox = checkbox
Set reCheckbox2 = CheckBox2
cTopPos(mCurrentPage) = cTopPos(mCurrentPage) + checkbox.height + 10
End Sub
Public Sub AddComboBox_Empty(reComboBox As msForms.ComboBox, Optional title As String = "Please Select", Optional tipText As String)
Dim label As msForms.label
Dim ComboBox As msForms.ComboBox
Set label = mfra(mCurrentPage).Controls.Add("Forms.Label.1")
'Set label = Me.Controls.Add("Forms.Label.1")
With label
.top = cTopPos(mCurrentPage)
'.top = 10
.left = pHoriSpace
.caption = title
.width = (Me.width - pHoriSpace) / 2 - pHoriSpace
.AutoSize = True
.ControlTipText = tipText
'AdjustLabelHeight label
'Debug.Print "Label Height = " & .Height
End With
Set ComboBox = mfra(mCurrentPage).Controls.Add("Forms.ComboBox.1")
With ComboBox
.height = Application.Max(label.height, 18)
.width = (Me.width - pHoriSpace) / 2 - pHoriSpace * 2
.top = cTopPos(mCurrentPage)
.left = (Me.width - pHoriSpace) / 2 + pHoriSpace
End With
If ComboBox.height > label.height Then
label.top = label.top + (ComboBox.height - label.height) / 2
End If
Set reComboBox = ComboBox
cTopPos(mCurrentPage) = cTopPos(mCurrentPage) + ComboBox.height + 10
End Sub
Sub AddComboBox(arr As Variant, reComboBox As msForms.ComboBox, Optional title As String = "Please Select", _
Optional defaultVal As Variant = vbNullString, Optional tipText As String)
AddComboBox_Empty reComboBox, title, tipText:=tipText
reComboBox.List = arr
If defaultVal = vbNullString Then
reComboBox.value = arr(0)
Else: reComboBox.value = defaultVal
End If
End Sub
Sub AddInputBox(reTextBox As msForms.Textbox, Optional title As String = "Please Input", Optional def_value As Variant)
Dim label As msForms.label
Dim Textbox As msForms.Textbox
Set label = mfra(mCurrentPage).Controls.Add("Forms.Label.1")
With label
.top = cTopPos(mCurrentPage)
.left = pHoriSpace
.caption = title
.width = (Me.width - pHoriSpace) / 2 - pHoriSpace
.AutoSize = True
End With
Set Textbox = mfra(mCurrentPage).Controls.Add("Forms.TextBox.1")
With Textbox
.height = Application.Max(label.height, 15)
.width = (Me.width - pHoriSpace) / 2 - pHoriSpace * 2
.top = cTopPos(mCurrentPage)
.left = (Me.width - pHoriSpace) / 2 + pHoriSpace
.value = def_value
End With
Set reTextBox = Textbox
cTopPos(mCurrentPage) = cTopPos(mCurrentPage) + Textbox.height + 10
End Sub
'Sub AddRefEdit(reRefEdit As refEdit.refEdit, Optional Title As String = "Please Input", Optional def_value As Variant)
'
' Dim label As MSForms.label
' Dim refEdit As refEdit.refEdit
'
' Set label = mfra(mCurrentPage).Controls.Add("Forms.Label.1")
' With label
' .top = cTopPos(mCurrentPage)
' .left = pHoriSpace
' .caption = Title
' .width = (Me.width - pHoriSpace) / 2 - pHoriSpace
' .AutoSize = True
' End With
'
' Set refEdit = mfra(mCurrentPage).Controls.Add("RefEdit.Ctrl")
' With refEdit
' .height = Application.Max(label.height, 30)
' .width = (Me.width - pHoriSpace) / 2 - pHoriSpace * 2
' .top = cTopPos(mCurrentPage)
' .left = (Me.width - pHoriSpace) / 2 + pHoriSpace
' .MultiLine = True
' .value = def_value
' End With
'
' Set reRefEdit = refEdit
' cTopPos(mCurrentPage) = cTopPos(mCurrentPage) + refEdit.height + 10
'End Sub
Public Sub AddSelectionBoxMulti_Empty(reListBox As msForms.listBox, Optional title As String = "listbox 1", _
Optional height_LB As Long = 140, Optional width_LB As Long, _
Optional width_cmdBtm As Long = 50, _
Optional is_reListBox2 As Boolean = False, Optional reListBox2 As msForms.listBox, _
Optional title2 As String = "listbox 2", _
Optional isCreateFrame As Boolean = False, Optional frameTitle As String = "", _
Optional reCmdBtn1 As msForms.CommandButton, Optional reCmdBtn2 As msForms.CommandButton)
'add the items
Dim newFrame As msForms.frame
Dim ListBox1 As msForms.listBox, ListBox2 As msForms.listBox
Dim cmdB1 As msForms.CommandButton, cmdB2 As msForms.CommandButton
Dim label As msForms.label, Label2 As msForms.label
Dim btnEvent As EventSelectionBoxMulti
Dim framePosX As Double, framePosY As Double
If width_LB = 0 Then
width_LB = Me.width / 2 - pHoriSpace * 2.5 - width_cmdBtm / 2
End If
If isCreateFrame Then
Set newFrame = mfra(mCurrentPage).Controls.Add("forms.frame.1", "TEST", True)
framePosX = 10
framePosY = 10
With newFrame
.caption = frameTitle
.top = cTopPos(mCurrentPage)
.left = pHoriSpace
.width = 2 * width_LB + 4 * pHoriSpace + width_cmdBtm + framePosX
.height = height_LB + framePosY + 15
.Font.Bold = True
End With
End If
Set label = mfra(mCurrentPage).Controls.Add("Forms.Label.1")
With label
.top = cTopPos(mCurrentPage) + framePosY
.left = pHoriSpace + framePosX
.caption = title
.width = width_LB + 5
.AutoSize = True
End With
Set ListBox1 = mfra(mCurrentPage).Controls.Add("Forms.ListBox.1")
With ListBox1
.height = height_LB
.width = width_LB
.top = cTopPos(mCurrentPage) + label.height + framePosY
.left = pHoriSpace + framePosX
.MultiSelect = fmMultiSelectExtended
End With
Set cmdB1 = mfra(mCurrentPage).Controls.Add("Forms.CommandButton.1")
With cmdB1
.caption = "->"
.height = height_LB / 4
.width = width_cmdBtm
.top = ListBox1.top + height_LB / 2 - 10 - .height
'.Top = cTopPos(mCurrentPage) + label.Height + height_LB / 2 - 10 - .Height
.left = ListBox1.left + ListBox1.width + pHoriSpace
End With
Set reCmdBtn1 = cmdB1
Set cmdB2 = mfra(mCurrentPage).Controls.Add("Forms.CommandButton.1")
With cmdB2
.caption = "<-"
.height = height_LB / 4
.width = width_cmdBtm
.top = ListBox1.top + height_LB / 2 + 10
.left = ListBox1.left + ListBox1.width + pHoriSpace
End With
Set reCmdBtn2 = cmdB2
Set Label2 = mfra(mCurrentPage).Controls.Add("Forms.Label.1")
With Label2
.top = cTopPos(mCurrentPage) + framePosY
.left = cmdB1.left + cmdB1.width + pHoriSpace + framePosX
.caption = title2
.width = width_LB
.AutoSize = True
End With
Set ListBox2 = mfra(mCurrentPage).Controls.Add("Forms.ListBox.1")
With ListBox2
.height = height_LB
.width = width_LB
.top = cTopPos(mCurrentPage) + label.height + framePosY
.left = cmdB1.left + cmdB1.width + pHoriSpace + framePosX
.MultiSelect = fmMultiSelectExtended
End With
'Set btnEvent = New EventSelectionBoxMulti
'btnEvent.Init Me, ListBox1, ListBox2, cmdB1, cmdB2
'eventHandlerCollection.Add btnEvent
'mColButtons.Add btnEvent
Set reListBox = ListBox1
If is_reListBox2 Then
Set reListBox2 = ListBox2
End If
'Resize windows
'Me.Width = Application.Max(Me.Width, width_cmdBtm + width_LB * 2 + pHoriSpace * 5 + framePosX * 3)
' Me.height = cTopPos + def_botMargin + height_LB + label.height + 15
cTopPos(mCurrentPage) = cTopPos(mCurrentPage) + height_LB + label.height + 10 + framePosY * 2
If isCreateFrame Then
newFrame.Visible = True
End If
End Sub
Sub AddSelectionBoxMulti(arr As Variant, reListBox As msForms.listBox, Optional title As String = "listbox 1", _
Optional title2 As String = "listbox 2", Optional height_LB As Long = 140, _
Optional width_LB As Long, Optional width_cmdBtm As Long = 50, _
Optional is_reListBox2 As Boolean = False, Optional reListBox2 As msForms.listBox, _
Optional isCreateFrame As Boolean = False, Optional frameTitle As String = "")
'add the items
Dim newFrame As msForms.frame
Dim ListBox1 As msForms.listBox, ListBox2 As msForms.listBox
Dim cmdB1 As msForms.CommandButton, cmdB2 As msForms.CommandButton
Dim label As msForms.label, Label2 As msForms.label
Dim btnEvent As EventSelectionBoxMulti
Dim framePosX As Double, framePosY As Double
If isCreateFrame Then
Set newFrame = mfra(mCurrentPage).Controls.Add("forms.frame.1", "TEST", True)
framePosX = 10
framePosY = 10
With newFrame
.caption = frameTitle
.top = cTopPos(mCurrentPage)
.left = pHoriSpace
.width = 2 * width_LB + 4 * pHoriSpace + width_cmdBtm + framePosX
.height = height_LB + framePosY + 15
.Font.Bold = True
End With
End If
Set label = mfra(mCurrentPage).Controls.Add("Forms.Label.1")
With label
.top = cTopPos(mCurrentPage) + framePosY
.left = pHoriSpace + framePosX
.caption = title
.width = width_LB + 5
.AutoSize = True
End With
Set ListBox1 = mfra(mCurrentPage).Controls.Add("Forms.ListBox.1")
With ListBox1
.height = height_LB
.width = width_LB
.top = cTopPos(mCurrentPage) + label.height + framePosY
.left = pHoriSpace + framePosX
.MultiSelect = fmMultiSelectExtended
.List = arr
End With
Set cmdB1 = mfra(mCurrentPage).Controls.Add("Forms.CommandButton.1")
With cmdB1
.caption = "->"
.height = height_LB / 4
.width = width_cmdBtm
.top = ListBox1.top + height_LB / 2 - 10 - .height
'.Top = cTopPos + label.Height + height_LB / 2 - 10 - .Height
.left = ListBox1.left + ListBox1.width + pHoriSpace
End With
Set cmdB2 = mfra(mCurrentPage).Controls.Add("Forms.CommandButton.1")
With cmdB2
.caption = "<-"
.height = height_LB / 4
.width = width_cmdBtm
.top = ListBox1.top + height_LB / 2 + 10
.left = ListBox1.left + ListBox1.width + pHoriSpace
End With
Set Label2 = mfra(mCurrentPage).Controls.Add("Forms.Label.1")
With Label2
.top = cTopPos(mCurrentPage) + framePosY
.left = cmdB1.left + cmdB1.width + pHoriSpace + framePosX
.caption = title2
.width = width_LB
.AutoSize = True
End With
Set ListBox2 = mfra(mCurrentPage).Controls.Add("Forms.ListBox.1")
With ListBox2
.height = height_LB
.width = width_LB
.top = cTopPos(mCurrentPage) + label.height + framePosY
.left = cmdB1.left + cmdB1.width + pHoriSpace + framePosX
.MultiSelect = fmMultiSelectExtended
End With
' Set btnEvent = New EventSelectionBoxMulti
' btnEvent.Init Me, ListBox1, ListBox2, cmdB1, cmdB2
' eventHandlerCollection.Add btnEvent
'mColButtons.Add btnEvent
Set reListBox = ListBox1
If is_reListBox2 Then
Set reListBox2 = ListBox2
End If
'Resize windows
Me.width = Application.Max(Me.width, width_cmdBtm + width_LB * 2 + pHoriSpace * 5 + framePosX * 3)
' Me.height = cTopPos + def_botMargin + height_LB + label.height + 15
cTopPos(mCurrentPage) = cTopPos(mCurrentPage) + height_LB + label.height + 10 + framePosY * 2
If isCreateFrame Then
newFrame.Visible = True
End If
End Sub
Sub AddComboBoxVisibilityControl(cb_master As msForms.ComboBox, _
cb_slave() As Object, val_visible As String)
Dim btnEvent As EventComboBoxControl
Set btnEvent = New EventComboBoxControl
btnEvent.Init Me, cb_master, cb_slave, val_visible
eventHandlerCollection.Add btnEvent
End Sub
Public Sub AdjustHeight()
Dim maxTopPos As Double, i As Integer
For i = 0 To UBound(cTopPos)
If cTopPos(i) > maxTopPos Then maxTopPos = cTopPos(i)
Next i
Me.height = maxTopPos + pBotMargin + OKButton.height + pVertSpace * 2 + 30
End Sub
Public Sub AddEvent(customEvent As Object)
eventHandlerCollection.Add customEvent
End Sub
'Private Sub AdjustLabelHeight(lb As MSForms.label)
' Dim minHeight As Double
' minHeight = 18
' If lb.Height < minHeight Then
' lb.AutoSize = False
' lb.Height = minHeight
' End If
'End Sub