-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNew-Form.psm1
More file actions
991 lines (778 loc) · 29.3 KB
/
New-Form.psm1
File metadata and controls
991 lines (778 loc) · 29.3 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
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
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
<#
.NOTES
Author: Moritz Grede
Last Edit: 2020-02-17
Version 1.0 - initial script
Version 1.1 - changed module name, added checkboxes
Version 2.0 - added radiobuttons, redid all functions with clearer parameter-statements
Version 2.1 - added inversion of booleans
Version 3.0 - added parameter sets, included layout functionality
Version 3.1 - added message, input & choice boxes
#>
# Adding .NET Framework type Forms to PowerShell
Add-Type -AssemblyName System.Windows.Forms
<#
.SYNOPSIS
Creates new color.
.DESCRIPTION
This function creates a new color based on red, green and blue integers between 0 and 255. 0 being lowest and 255 being highest.
.PARAMETER RGB
The x-coordinate (horizontal position).
.EXAMPLE
PS C:\> New-Color -RGB @(0,128,255)
PS C:\> New-Color -Red 0 -Green 128 -Blue 255
#>
Function New-Color {
Param (
[Parameter(Mandatory = $true, ParameterSetName = 'Array')][System.Object[]] $RGB,
[Parameter(ParameterSetName = 'Single')][ValidateRange(0, 255)][Int16] $Red = 0,
[Parameter(ParameterSetName = 'Single')][ValidateRange(0, 255)][Int16] $Green = 0,
[Parameter(ParameterSetName = 'Single')][ValidateRange(0, 255)][Int16] $Blue = 0
)
# Create and return color
Switch ( $PSCmdlet.ParameterSetName ) {
'Array' {
$Color = [System.Drawing.Color]::FromArgb(255, $RGB[0], $RGB[1], $RGB[2])
}
'Single' {
$Color = [System.Drawing.Color]::FromArgb(255, $Red, $Green, $Blue)
}
}
If ( $null -ne $Color ) { Return $Color }
Else { Return [System.Drawing.Color]::Empty }
}
<#
.SYNOPSIS
Create new drawing point.
.DESCRIPTION
This function creates a new drawing point using two given coordinates as integers.
.PARAMETER X
X-coordinate (horizontal position).
.PARAMETER Y
Y-coordinate (vertical position).
.EXAMPLE
PS C:\> New-DrawingPoint -X 5 -Y 5
#>
Function New-DrawingPoint {
Param (
[Parameter(Mandatory = $true)][ValidateNotNull()][Int] $X,
[Parameter(Mandatory = $true)][ValidateNotNull()][Int] $Y
)
# Create and return a system drawing point
Return New-Object System.Drawing.Point($X,$Y)
}
<#
.SYNOPSIS
Create a new form.
.DESCRIPTION
This function creates a new form.
.PARAMETER Title
Title of the window.
.PARAMETER WindowState
State of the created window. Can be 'Normal', 'Maximized' or 'Minimized'.
.PARAMETER StartPosition
Start position of the created window. Can be 'CenterScreen', 'Manual', 'WindowsDefaultLocation', 'WindowsDefaultBounds' or 'CenterParent'.
.PARAMETER HideInTaskbar
Wether to hide the icon in taskbar.
.PARAMETER Height
Height of the form.
.PARAMETER Width
Width of the form.
.PARAMETER AutoSize
Wether the window should automatically resize depending on its content.
.PARAMETER Font
Default font for all later components in the form.
.PARAMETER FrontColor
Default foreground color for all later components in the form.
.EXAMPLE
PS C:\> New-Form -Title 'Form' -WindowState 'Normal' -StartPosition 'CenterScreen' -Height 200 -Width 400 -AutoSize -Font (New-Object System.Drawing.Font("Consolas", 12, [System.Drawing.FontStyle]::Regular))
#>
Function New-Form {
Param (
[String] $Title = '',
[ValidateSet('Normal', 'Maximized', 'Minimized')][System.Windows.Forms.FormWindowState] $WindowState = [System.Windows.Forms.FormWindowState]::Normal,
[ValidateSet('CenterScreen', 'Manual', 'WindowsDefaultLocation', 'WindowsDefaultBounds', 'CenterParent')][System.Windows.Forms.FormStartPosition] $StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen,
[Switch] $HideInTaskbar,
[Int] $Height = 0,
[Int] $Width = 0,
[Switch] $AutoSize,
[System.Drawing.Font] $Font = ( New-Object System.Drawing.Font( "Consolas", 12, [System.Drawing.FontStyle]::Regular ) ),
[System.Drawing.Color] $FrontColor = [System.Drawing.Color]::BLACK
)
# Invert boolean
$HideInTaskbar = -not $HideInTaskbar
# Create form
$Form = New-Object System.Windows.Forms.Form
$Form.Text = $Title
$Form.WindowState = $WindowState
$Form.StartPosition = $StartPosition
$Form.ShowInTaskbar = $HideInTaskbar
$Form.Height = $Height
$Form.Width = $Width
$Form.AutoSize = $AutoSize
$Form.Padding = 10
$Form.Font = $Font
$Form.ForeColor = $FrontColor
# Return created form
Return $Form
}
<#
.SYNOPSIS
Create a new panel.
.DESCRIPTION
This function creates a new panel.
.PARAMETER X
X-coordinate (horizontal position) of the panel.
.PARAMETER Y
Y-coordinate (vertical position) of the panel.
.PARAMETER Height
Height of the panel.
.PARAMETER Width
Width of the panel.
.PARAMETER AutoSizeMode
How the panel should grow when AutoSize is enabled. Can be 'GrowAndShrink' or 'GrowOnly'
.PARAMETER AutoSize
Wether or not the panel should automatically change size depending on its content.
.PARAMETER AutoScroll
Wether to always show the scrollbar in the panel.
.PARAMETER TableLayout
Creates a TableLayoutPanel. Shorthand is New-TableLayoutPanel
.PARAMETER FlowLayout
Creates a FlowLayoutPanel. Shorthand is New-FlowLayoutPanel
.EXAMPLE
PS C:\> New-Panel -X 5 -Y 5 -Height 100 -Width 150 -AutoSizeMode 'GrowOnly' -AutoSize
PS C:\> New-Panel -AutoSize -TableLayout
PS C:\> New-Panel -AutoSize -FlowLayout
#>
Function New-Panel {
Param (
[Parameter(Mandatory = $true, ParameterSetName = 'Manual')][ValidateNotNullOrEmpty()][int] $X,
[Parameter(Mandatory = $true, ParameterSetName = 'Manual')][ValidateNotNullOrEmpty()][int] $Y,
[Parameter(Mandatory = $false, ParameterSetName = 'Manual')][ValidateNotNullOrEmpty()][Int] $Height = 0,
[Parameter(Mandatory = $false, ParameterSetName = 'Manual')][ValidateNotNullOrEmpty()][Int] $Width = 0,
[ValidateNotNull()][Int] $Padding = 0,
[ValidateSet('GrowAndShrink', 'GrowOnly')][System.Windows.Forms.AutoSizeMode] $AutoSizeMode = [System.Windows.Forms.AutoSizeMode]::GrowAndShrink,
[Switch] $AutoSize,
[Switch] $AutoScroll,
[Parameter(Mandatory = $true, ParameterSetName = 'TableLayout')][Switch] $TableLayout,
[Parameter(Mandatory = $true, ParameterSetName = 'FlowLayout')][Switch] $FlowLayout
)
# Create panel
Switch ( $PSCmdlet.ParameterSetName ) {
'Manual' {
$Panel = New-Object System.Windows.Forms.Panel
$Panel.Location = New-DrawingPoint -X $X -Y $Y
$Panel.Height = $Height
$Panel.Width = $Width
}
'TableLayout' {
$Panel = New-Object System.Windows.Forms.TableLayoutPanel
$Panel.Dock = [System.Windows.Forms.DockStyle]::Fill
}
'FlowLayout' {
$Panel = New-Object System.Windows.Forms.FlowLayoutPanel
$Panel.Dock = [System.Windows.Forms.DockStyle]::Fill
}
}
# Set panel properties
$Panel.AutoScroll = $AutoScroll
$Panel.AutoSize = $AutoSize
$Panel.AutoSizeMode = $AutoSizeMode
$Panel.BorderStyle = 'FixedSingle'
$Panel.Padding = $Padding
# Return created panel
Return $Panel
}
<#
.SYNOPSIS
Create a new panel.
.DESCRIPTION
This function creates a new table layout panel.
.PARAMETER AutoSizeMode
How the panel should grow when AutoSize is enabled. Can be 'GrowAndShrink' or 'GrowOnly'
.PARAMETER AutoSize
Wether or not the panel should automatically change size depending on its content.
.PARAMETER AutoScroll
Wether to always show the scrollbar in the panel.
.EXAMPLE
PS C:\> New-TableLayoutPanel -AutoSize
#>
Function New-TableLayoutPanel {
Param (
[ValidateSet('GrowAndShrink', 'GrowOnly')][System.Windows.Forms.AutoSizeMode] $AutoSizeMode = [System.Windows.Forms.AutoSizeMode]::GrowAndShrink,
[Switch] $AutoSize,
[Switch] $AutoScroll
)
# Call panel function and return created panel
Return ( New-Panel -TableLayout -AutoSizeMode $AutoSizeMode -AutoSize:$AutoSize -AutoScroll:$AutoScroll )
}
<#
.SYNOPSIS
Create a new panel.
.DESCRIPTION
This function creates a new flow layout panel.
.PARAMETER AutoSizeMode
How the panel should grow when AutoSize is enabled. Can be 'GrowAndShrink' or 'GrowOnly'
.PARAMETER AutoSize
Wether or not the panel should automatically change size depending on its content.
.PARAMETER AutoScroll
Wether to always show the scrollbar in the panel.
.EXAMPLE
PS C:\> New-FlowLayoutPanel -AutoSize
#>
Function New-FlowLayoutPanel {
Param (
[ValidateSet('GrowAndShrink', 'GrowOnly')][System.Windows.Forms.AutoSizeMode] $AutoSizeMode = [System.Windows.Forms.AutoSizeMode]::GrowAndShrink,
[Switch] $AutoSize,
[Switch] $AutoScroll
)
# Call panel function and return created panel
Return ( New-Panel -FlowLayout -AutoSizeMode $AutoSizeMode -AutoSize:$AutoSize -AutoScroll:$AutoScroll )
}
<#
.SYNOPSIS
Create a new label.
.DESCRIPTION
This function creates a new label.
.PARAMETER X
X-coordinate (horizontal position) of the label.
.PARAMETER Y
Y-coordinate (vertical position) of the label.
.PARAMETER Text
Text to be displayed.
.PARAMETER Height
Height of the label.
.PARAMETER Width
Width of the label.
.PARAMETER FrontColor
Foreground color of the label.
.PARAMETER BackColor
Background color of the label.
.PARAMETER Align
Where to align the labels content. Can be 'Top', 'Middle' or 'Bottom' directly followed by 'Left', 'Center' or 'Right'. First defines vertical position, second horizontal.
.PARAMETER AutoSize
Wether or not the label should automatically change size depending on its content.
.PARAMETER Dock
If in a Table- or FlowLayoutPanel, where to dock the label to.
.EXAMPLE
PS C:\> New-Label -X 5 -Y 5 -Text 'Label' -Height 20 -Width 100 -FrontColor 'BLACK' -Align 'MiddleLeft'
#>
Function New-Label {
Param (
[Int] $X = 0,
[Int] $Y = 0,
[Parameter(Mandatory = $true)][ValidateNotNull()][String] $Text,
[Int] $Height = 0,
[Int] $Width = 0,
[String] $FrontColor = $null,
[String] $BackColor = $null,
[ValidateSet( 'TopLeft', 'TopCenter', 'TopRight', 'MiddleLeft', 'MiddleCenter', 'MiddleRight', 'BottomLeft', 'BottomCenter', 'BottomRight' )][System.Drawing.ContentAlignment] $Align = [System.Drawing.ContentAlignment]::MiddleLeft,
[Switch] $AutoSize,
[ValidateSet( 'Bottom', 'Fill', 'Left', 'None', 'Right', 'Top' )][System.Windows.Forms.DockStyle] $Dock = [System.Windows.Forms.DockStyle]::Fill
)
# Create label
$Label = New-Object System.Windows.Forms.Label
$Label.AutoSize = $AutoSize
$Label.BackColor = $BackColor
$Label.ForeColor = $FrontColor
$Label.Height = $Height
$Label.Location = New-DrawingPoint -X $X -Y $Y
$Label.Text = $Text
$Label.TextAlign = $Align
$Label.Width = $Width
# Return created label
Return $Label
}
<#
.SYNOPSIS
Create a new textbox.
.DESCRIPTION
This function creates a new textbox.
.PARAMETER X
X-coordinate (horizontal position) of the textbox.
.PARAMETER Y
Y-coordinate (vertical position) of the textbox.
.PARAMETER Text
Text to be displayed in the textbox.
.PARAMETER Height
Height of the textbox.
.PARAMETER Width
Width of the textbox.
.PARAMETER FrontColor
Foreground color of the textbox.
.PARAMETER BackColor
Background color of the textbox.
.PARAMETER Align
Where to align the textboxes content. Can be 'Top', 'Middle' or 'Bottom' directly followed by 'Left', 'Center' or 'Right'. First defines vertical position, second defines horizontal.
.PARAMETER Disabled
Disables the textbox.
.PARAMETER ReadOnly
Textbox will not be editable.
.PARAMETER Dock
If in a Table- or FlowLayoutPanel, where to dock the label to.
.EXAMPLE
PS C:\> New-TextBox -X 5 -Y 5 -Height 20 -Width 150 -FrontColor 'BLACK' -Align 'MiddleLeft'
#>
Function New-TextBox {
Param (
[Int] $X = 0,
[Int] $Y = 0,
[String] $Text = '',
[Int] $Height = 0,
[Int] $Width = 0,
[System.Drawing.Color] $FrontColor = [System.Drawing.Color]::Empty,
[System.Drawing.Color] $BackColor = [System.Drawing.Color]::Empty,
[ValidateSet('TopLeft','TopCenter','TopRight','MiddleLeft','MiddleCenter','MiddleRight','BottomLeft','BottomCenter','BottomRight')][System.Windows.Forms.HorizontalAlignment] $Align = [System.Windows.Forms.HorizontalAlignment]::Left,
[Switch] $Disabled,
[Switch] $ReadOnly,
[ValidateSet( 'Bottom', 'Fill', 'Left', 'None', 'Right', 'Top' )][System.Windows.Forms.DockStyle] $Dock = [System.Windows.Forms.DockStyle]::Fill
)
# Invert booleans
$Disabled = -not $Disabled
# Create textbox
$Textbox = New-Object System.Windows.Forms.TextBox
$Textbox.BackColor = $BackColor
$Textbox.Dock = [System.Windows.Forms.DockStyle]::Fill
$Textbox.Enabled = $Disabled
$Textbox.ForeColor = $FrontColor
$Textbox.Height = $Height
$Textbox.Location = New-DrawingPoint -X $X -Y $Y
$Textbox.ReadOnly = $ReadOnly
$Textbox.Text = $Text
$Textbox.TextAlign = $Align
$Textbox.Width = $Width
# Return created textbox
Return $Textbox
}
<#
.SYNOPSIS
Create a new button.
.DESCRIPTION
This function creates a new button.
.PARAMETER X
X-coordinate (horizontal position) of the button.
.PARAMETER Y
Y-coordinate (vertical position) of the button.
.PARAMETER Text
Text to be displayed in the button.
.PARAMETER Height
Height of the button.
.PARAMETER Width
Width of the button.
.PARAMETER Disabled
Disables the button.
.PARAMETER Dock
If in a Table- or FlowLayoutPanel, where to dock the label to.
.EXAMPLE
PS C:\> New-Button -X 5 -Y 5 -Text 'Button' -Height 20 -Width 100
#>
Function New-Button {
Param (
[Int] $X = 0,
[Int] $Y = 0,
[String] $Text = '',
[Int] $Height = 0,
[Int] $Width = 0,
[Switch] $Disabled,
[ValidateSet( 'Bottom', 'Fill', 'Left', 'None', 'Right', 'Top' )][System.Windows.Forms.DockStyle] $Dock = [System.Windows.Forms.DockStyle]::Fill
)
# Invert booleans
$Disabled = -not $Disabled
# Create the button
$Button = New-Object System.Windows.Forms.Button
$Button.Dock = [System.Windows.Forms.DockStyle]::Fill
$Button.Enabled = $Disabled
$Button.Height = $Height
$Button.Location = New-DrawingPoint -X $X -Y $Y
$Button.Text = $Text
$Button.Width = $Width
# Return the button
Return $Button
}
<#
.SYNOPSIS
Create a new listbox.
.DESCRIPTION
This function creates a new listbox.
.PARAMETER X
X-coordinate (horizontal position) of the listbox.
.PARAMETER Y
Y-coordinate (vertical position) of the listbox.
.PARAMETER Height
Height of the listbox.
.PARAMETER Width
Width of the listbox.
.PARAMETER ColWidth
Width of the displayed column(s).
.PARAMETER SelectionMode
Can be 'MultiExtended' (multiple may be selected, modifier keys CTRL & SHIFT may be used), 'MultiSimple' (multiple may be selected), 'None' (nothing can be selected) or 'One' (one item may be selected).
.PARAMETER Disabled
Disables the listbox.
.PARAMETER AutoSize
Adjust the listboxes size depending on its content.
.PARAMETER Sorted
Sort the listbox.
.PARAMETER MultiCol
Allow multiple columns.
.PARAMETER Dock
If in a Table- or FlowLayoutPanel, where to dock the label to.
.EXAMPLE
PS C:\> New-ListBox -X 5 -Y 5 -Height 300 -Width 200 -ColWidth 100 -SelectionMode 'One' -AutoSize -Sorted -MultiCol
#>
Function New-ListBox {
Param (
[Int] $X = 0,
[Int] $Y = 0,
[Int] $Height = 0,
[Int] $Width = 0,
[Int] $ColWidth = $Width,
[ValidateSet('MultiExtended','MultiSimple','None','One')][System.Windows.Forms.SelectionMode] $SelectionMode = [System.Windows.Forms.SelectionMode]::One,
[Switch] $Disabled,
[Switch] $AutoSize,
[Switch] $Sorted,
[Switch] $MultiCol,
[ValidateSet( 'Bottom', 'Fill', 'Left', 'None', 'Right', 'Top' )][System.Windows.Forms.DockStyle] $Dock = [System.Windows.Forms.DockStyle]::Fill
)
# Invert booleans
$Disabled = -not $Disabled
# Create listbox
$ListBox = New-Object System.Windows.Forms.ListBox
$ListBox.AutoSize = $AutoSize
$ListBox.ColumnWidth = $ColWidth
$ListBox.Dock = [System.Windows.Forms.DockStyle]::Fill
$ListBox.Enabled = $Disabled
$ListBox.Height = $Height
$ListBox.Location = New-DrawingPoint -X $X -Y $Y
$ListBox.MultiColumn = $MultiCol
$ListBox.SelectionMode = $SelectionMode
$ListBox.Sorted = $Sorted
$ListBox.Width = $Width
# Return created listbox
Return $ListBox
}
<#
.SYNOPSIS
Create a new dropdown.
.DESCRIPTION
This function creates a new dropdown.
.PARAMETER X
X-coordinate (horizontal position) of the dropdown.
.PARAMETER Y
Y-coordinate (vertical position) of the dropdown.
.PARAMETER Height
Height of the dropdown.
.PARAMETER Width
Width of the dropdown.
.PARAMETER MaxDropItems
Amount of items to display when dropped down.
.PARAMETER AutoSize
Automatically adjust the dropdowns size depending on its content.
.PARAMETER Disabled
Disables the dropdown list.
.PARAMETER Sorted
Sort the dropdown items.
.PARAMETER Dock
If in a Table- or FlowLayoutPanel, where to dock the label to.
.EXAMPLE
PS C:\> New-Dropdown -X 5 -Y 5 -Height 20 -Width 200 -DropHeight 100 -DropWidth 300 -ItemHeight 20 -MaxDropItems 10 -Sorted
#>
Function New-Dropdown {
Param (
[Int] $X = 0,
[Int] $Y = 0,
[Int] $Height = 0,
[Int] $Width = 0,
[Int] $MaxDropItems = 1,
[Switch] $AutoSize,
[Switch] $Disabled,
[Switch] $Sorted,
[ValidateSet( 'Bottom', 'Fill', 'Left', 'None', 'Right', 'Top' )][System.Windows.Forms.DockStyle] $Dock = [System.Windows.Forms.DockStyle]::Fill
)
# Invert booleans
$Disabled = -not $Disabled
# Create dropdown
$Dropdown = New-Object System.Windows.Forms.ComboBox
$Dropdown.AutoSize = $AutoSize
$Dropdown.Dock = [System.Windows.Forms.DockStyle]::Fill
$Dropdown.Enabled = $Disabled
$Dropdown.Height = $Height
$Dropdown.Location = New-DrawingPoint -X $X -Y $Y
$Dropdown.MaxDropDownItems = $MaxDropItems
$Dropdown.Sorted = $Sorted
$Dropdown.Width = $Width
# Return created dropdown
Return $Dropdown
}
<#
.SYNOPSIS
Create a new checkbox.
.DESCRIPTION
This function creates a new checkbox.
.PARAMETER X
X-coordinate (horizontal position) of the radio button.
.PARAMETER Y
Y-coordinate (vertical position) of the radio button.
.PARAMETER Text
Text to be displayed behind the radio button.
.PARAMETER Height
Height of the radio button.
.PARAMETER Width
Width of the radio button.
.PARAMETER Checked
Checkbox is initially checked.
.PARAMETER Dock
If in a Table- or FlowLayoutPanel, where to dock the label to.
.EXAMPLE
PS C:\> New-Checkbox -X 5 -Y 5 -Text 'Box' -Height 20 -Width 200 -Checked
#>
Function New-Checkbox {
Param (
[Int] $X = 0,
[Int] $Y = 0,
[String] $Text = '',
[Int] $Height = 0,
[Int] $Width = 0,
[Switch] $Checked,
[ValidateSet( 'Bottom', 'Fill', 'Left', 'None', 'Right', 'Top' )][System.Windows.Forms.DockStyle] $Dock = [System.Windows.Forms.DockStyle]::Fill
)
# Create checkbox
$Checkbox = New-Object System.Windows.Forms.CheckBox
$Checkbox.Checked = $Checked
$Checkbox.Dock = [System.Windows.Forms.DockStyle]::Fill
$Checkbox.Height = $Height
$Checkbox.Location = New-DrawingPoint -X $X -Y $Y
$Checkbox.Text = $Text
$Checkbox.Width = $Width
# Return checkbox
Return $Checkbox
}
<#
.SYNOPSIS
Create a new radio button.
.DESCRIPTION
This function creates a new radio button.
.PARAMETER X
X-coordinate (horizontal position) of the radio button.
.PARAMETER Y
Y-coordinate (vertical position) of the radio button.
.PARAMETER Text
Text to be displayed behind the radio button.
.PARAMETER Height
Height of the radio button.
.PARAMETER Width
Width of the radio button.
.PARAMETER Checked
Radio button is initally checked.
.PARAMETER Disabled
Disables the radio button.
.PARAMETER AutoSize
Automatically adjust the radio buttons size depending on the content.
.PARAMETER Dock
If in a Table- or FlowLayoutPanel, where to dock the label to.
.EXAMPLE
PS C:\> New-RadioButton -X 5 -Y 5 -Text 'Button' -Height 20 -Width 200 -Checked -AutoSize
#>
Function New-RadioButton {
Param (
[Int] $X = 0,
[Int] $Y = 0,
[String] $Text = '',
[Int] $Height = 0,
[Int] $Width = 0,
[Switch] $Checked,
[Switch] $Disabled,
[Switch] $AutoSize,
[ValidateSet( 'Bottom', 'Fill', 'Left', 'None', 'Right', 'Top' )][System.Windows.Forms.DockStyle] $Dock = [System.Windows.Forms.DockStyle]::Fill
)
# Invert booleans
$Disabled = -not $Disabled
# Create radio button
$Radio = New-Object System.Windows.Forms.RadioButton
$Radio.AutoSize = $AutoSize
$Radio.Checked = $Checked
$Radio.Dock = [System.Windows.Forms.DockStyle]::Fill
$Radio.Enabled = $Disabled
$Radio.Height = $Height
$Radio.Location = New-DrawingPoint -X $X -Y $Y
$Radio.Text = $Text
$Radio.Width = $Width
# Return radio button
Return $Radio
}
<#
.SYNOPSIS
Create a message box.
.DESCRIPTION
This function creates a message box.
.PARAMETER Title
Title of the message window.
.PARAMETER Message
Message to be displayed.
.PARAMETER ButtonText
Text to be displayed in the confirmation button.
.PARAMETER WindowState
State of the created window. Can be 'Normal', 'Maximized' or 'Minimized'.
.PARAMETER StartPosition
Start position of the created window. Can be 'CenterScreen', 'Manual', 'WindowsDefaultLocation', 'WindowsDefaultBounds' or 'CenterParent'.
.PARAMETER HideInTaskbar
Hide the icon in taskbar.
.EXAMPLE
PS C:\> New-MsgBox -Title 'Information' -Message 'Information message' -ButtonText 'Ok' -HideInTaskbar
#>
Function New-MsgBox {
Param (
[String] $Title = '',
[String] $Message = '',
[String] $ButtonText = 'Ok',
[ValidateSet( 'Normal', 'Maximized', 'Minimized' )][System.Windows.Forms.FormWindowState] $WindowState = [System.Windows.Forms.FormWindowState]::Normal,
[ValidateSet( 'CenterScreen', 'Manual', 'WindowsDefaultLocation', 'WindowsDefaultBounds', 'CenterParent' )][System.Windows.Forms.FormStartPosition] $StartPosition = [System.Windows.Forms.FormStartPosition]::CenterParent,
[Switch] $HideInTaskbar
)
# Create form
$Form = New-Form -Title $Title -WindowState $WindowState -StartPosition $StartPosition -AutoSize -HideInTaskbar:$HideInTaskbar
$Form.Padding = 0
# Create TableLayoutPanel
$Panel = New-TableLayoutPanel -AutoSize
$Panel.GrowStyle = [System.Windows.Forms.TableLayoutPanelGrowStyle]::AddRows
$Panel.Dock = [System.Windows.Forms.DockStyle]::Fill
# Create textfield for message
$Text = New-TextBox -Text $Message -ReadOnly
$Text.AutoSize = $true
$Text.MultiLine = $true
$Text.Dock = [System.Windows.Forms.DockStyle]::Fill
$Panel.Controls.Add( $Text )
# Create button
$Button = New-Button -Text $ButtonText
#$Button.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom
$Button.Add_Click( { $this.Parent.Parent.Close()})
$Panel.Controls.Add( $Button )
$Form.AcceptButton = $Button
$Form.Controls.Add($Panel)
# Layout operations
$Panel.RowStyles.Add( ( New-Object System.Windows.Forms.RowStyle( [System.Windows.Forms.SizeType]::Percent, 100 ) ) ) > $null
$Panel.RowStyles.Add( ( New-Object System.Windows.Forms.RowStyle( [System.Windows.Forms.SizeType]::AutoSize ) ) ) > $null
# Return created form
Return $Form
}
<#
.SYNOPSIS
Creates an input box.
.DESCRIPTION
This function creates an input box.
.PARAMETER Title
Title of the window.
.PARAMETER Message
Message to be displayed.
.PARAMETER ButtonText
Text to be displayed in the confirmation button.
.PARAMETER WindowState
State of the created window. Can be 'Normal', 'Maximized' or 'Minimized'.
.PARAMETER StartPosition
Start position of the created window. Can be 'CenterScreen', 'Manual', 'WindowsDefaultLocation', 'WindowsDefaultBounds' or 'CenterParent'.
.PARAMETER HideInTaskbar
Hides the icon in taskbar.
.EXAMPLE
PS C:\> New-InputBox -Title 'Input' -Message 'Input message' -ButtonText 'Ok' -HideInTaskbar
#>
Function New-InputBox {
Param (
[String] $Title = '',
[String] $Message = '',
[String] $ButtonText = 'Ok',
[ValidateSet( 'Normal', 'Maximized', 'Minimized' )][System.Windows.Forms.FormWindowState] $WindowState = [System.Windows.Forms.FormWindowState]::Normal,
[ValidateSet( 'CenterScreen', 'Manual', 'WindowsDefaultLocation', 'WindowsDefaultBounds', 'CenterParent' )][System.Windows.Forms.FormStartPosition] $StartPosition = [System.Windows.Forms.FormStartPosition]::CenterParent,
[Switch] $HideInTaskbar
)
# Create form
$Form = New-Form -Title $Title -WindowState $WindowState -StartPosition $StartPosition -AutoSize -HideInTaskbar:$HideInTaskbar
$Form.Padding = 0
# Create TableLayoutPanel
$Panel = New-TableLayoutPanel -AutoSize
$Panel.GrowStyle = [System.Windows.Forms.TableLayoutPanelGrowStyle]::AddRows
# Create textbox for message
$Text = New-TextBox -Text $Message -AutoSize -ReadOnly
$Text.MultiLine = $true
$Text.Name = 'Message'
$Panel.Controls.Add( $Text)
# Create textfield for input
$Input = New-TextBox -AutoSize
$Input.Name = 'Input'
$Panel.Controls.Add( $Input )
# Create button
$Button = New-Button -Text $ButtonText -AutoSize
$Button.Add_Click( { $this.Parent.Controls | ForEach-Object { If ( 'Input' -eq $_.Name ) { $_.Text } }; $this.Parent.Parent.Close() } )
$Panel.Controls.Add( $Button )
$Form.AcceptButton = $Button
$Form.Controls.Add( $Panel )
# Layout operations
$Panel.RowStyles.Add( ( New-Object System.Windows.Forms.RowStyle( [System.Windows.Forms.SizeType]::Percent, 100 ) ) ) | Out-Null
$Panel.RowStyles.Add( ( New-Object System.Windows.Forms.RowStyle( [System.Windows.Forms.SizeType]::Absolute, 25 ) ) ) | Out-Null
$Panel.RowStyles.Add( ( New-Object System.Windows.Forms.RowStyle( [System.Windows.Forms.SizeType]::Absolute, 30 ) ) ) | Out-Null
# Return created form
Return $Form
}
<#
.SYNOPSIS
Create a choice box.
.DESCRIPTION
This function creates a choice box.
.PARAMETER Title
Title of the window.
.PARAMETER Message
Message to be displayed.
.PARAMETER ButtonConfirm
Text to be displayed in the confirmation button.
.PARAMETER ButtonDeny
Text to be displayed in the deny button.
.PARAMETER WindowState
State of the created window. Can be 'Normal', 'Maximized' or 'Minimized'.
.PARAMETER StartPosition
Start position of the created window. Can be 'CenterScreen', 'Manual', 'WindowsDefaultLocation', 'WindowsDefaultBounds' or 'CenterParent'.
.PARAMETER HideInTaskbar
Hides the icon in taskbar.
.EXAMPLE
PS C:\> New-ChoiceBox -Title 'Choice' -Message 'Choice message' -ButtonConfirmation 'Yes' -HideInTaskbar
#>
Function New-ChoiceBox {
Param (
[String] $Title = '',
[String] $Message = '',
[String] $ButtonConfirm = 'Yes',
[String] $ButtonDeny = 'No',
[ValidateSet('Normal', 'Maximized', 'Minimized')][System.Windows.Forms.FormWindowState] $WindowState = [System.Windows.Forms.FormWindowState]::Normal,
[ValidateSet('CenterScreen', 'Manual', 'WindowsDefaultLocation', 'WindowsDefaultBounds', 'CenterParent')][System.Windows.Forms.FormStartPosition] $StartPosition = [System.Windows.Forms.FormStartPosition]::CenterParent,
[Switch] $HideInTaskbar
)
# Create form
$Form = New-Form -Title $Title -WindowState $WindowState -StartPosition $StartPosition -AutoSize -HideInTaskbar:$HideInTaskbar
$Form.Padding = 0
# Create TableLayoutPanel
$Panel = New-TableLayoutPanel -AutoSize
$Panel.ColumnCount = 2
$Panel.GrowStyle = [System.Windows.Forms.TableLayoutPanelGrowStyle]::AddRows
$Panel.Dock = [System.Windows.Forms.DockStyle]::Fill
# Create textfield for message
$Text = New-TextBox -Text $Message -ReadOnly
$Text.AutoSize = $true
$Text.MultiLine = $true
$Panel.Controls.Add( $Text )
# Create confirmation button
$Confirm = New-Button -Text $ButtonConfirm
$Confirm.Add_Click( { 'Accept'; $this.Parent.Close() } )
$Panel.Controls.Add( $Confirm )
$Form.AcceptButton = $Confirm
# Create deny button
$Deny = New-Button -Text $ButtonDeny
$Deny.Add_Click( { $this.Parent.Close() } )
$Panel.Controls.Add( $Deny )
$Form.CancelButton = $Deny
$Form.Controls.Add($Panel)
# Layout operations
$Panel.SetColumnSpan( $Text, 2 )
$Panel.ColumnStyles.Add( ( New-Object System.Windows.Forms.RowStyle( [System.Windows.Forms.SizeType]::Percent, 50 ) ) ) > $null
$Panel.ColumnStyles.Add( ( New-Object System.Windows.Forms.RowStyle( [System.Windows.Forms.SizeType]::Percent, 50 ) ) ) > $null
$Panel.RowStyles.Add( ( New-Object System.Windows.Forms.RowStyle( [System.Windows.Forms.SizeType]::Percent, 100 ) ) ) > $null
$Panel.RowStyles.Add( ( New-Object System.Windows.Forms.RowStyle( [System.Windows.Forms.SizeType]::AutoSize ) ) ) > $null
# Return created form
Return $Form
}