-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponsive.ps1
More file actions
1359 lines (1062 loc) · 39.7 KB
/
Copy pathresponsive.ps1
File metadata and controls
1359 lines (1062 loc) · 39.7 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
992
993
994
995
996
997
998
999
1000
<###
.SYNOPSIS
Responsive GUI Helper Script for PowerShell Windows Forms Applications
.DESCRIPTION
This helper script provides comprehensive responsive GUI functionality for PowerShell scripts.
It automatically handles DPI scaling, resolution detection, and responsive control sizing
for all screen resolutions from VGA (640x480) to 8K UHD (7680x4320).
This script is designed to be called from other PowerShell scripts via GitHub URL or local path.
It follows the myTech.Today GUI responsiveness standards from .augment/gui-responsiveness.md
.USAGE
# Method 1: Call from GitHub (recommended for distributed scripts)
$responsiveUrl = 'https://raw.githubusercontent.com/mytech-today-now/PowerShellScripts/main/scripts/responsive.ps1'
Invoke-Expression (Invoke-WebRequest -Uri $responsiveUrl -UseBasicParsing).Content
# Method 2: Dot-source from local path (for development)
. "$PSScriptRoot\..\scripts\responsive.ps1"
# Then use the functions in your script:
$scaleInfo = Get-ResponsiveDPIScale
$form = New-ResponsiveForm -Title "My App" -Width 800 -Height 600
$button = New-ResponsiveButton -Text "Click Me" -X 20 -Y 20
.NOTES
File Name : responsive.ps1
Author : myTech.Today
Prerequisite : PowerShell 5.1 or later, Windows Forms
Copyright : (c) 2025 myTech.Today. All rights reserved.
Version : 1.0.0
.LINK
https://github.com/mytech-today-now/PowerShellScripts
#>
#Requires -Version 5.1
# Ensure Windows Forms assemblies are loaded
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# Module-level variables for caching
$script:CachedScaleInfo = $null
$script:CachedBaseDimensions = $null
#region Core DPI and Scaling Functions
function Get-ResponsiveDPIScale {
<#
.SYNOPSIS
Calculates DPI scaling factor based on screen resolution and DPI settings.
.DESCRIPTION
Detects screen resolution and DPI, then calculates appropriate scaling factor.
Supports VGA through 8K UHD displays with progressive scaling.
Results are cached for performance.
.PARAMETER Force
Force recalculation even if cached value exists.
.OUTPUTS
PSCustomObject with scaling information:
- BaseFactor: Base DPI scaling factor
- AdditionalScale: Resolution-specific additional scaling
- TotalScale: Combined scaling factor to apply to all dimensions
- ScreenWidth: Screen width in pixels
- ScreenHeight: Screen height in pixels
- DpiX: Horizontal DPI
- DpiY: Vertical DPI
- ResolutionName: Detected resolution category name
- ResolutionCategory: Category (VGA, HD, FHD, 4K, etc.)
.EXAMPLE
$scale = Get-ResponsiveDPIScale
Write-Host "Screen: $($scale.ScreenWidth)x$($scale.ScreenHeight)"
Write-Host "Resolution: $($scale.ResolutionName)"
Write-Host "Scale Factor: $($scale.TotalScale)"
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $false)]
[switch]$Force
)
# Return cached value if available and not forcing recalculation
if ($script:CachedScaleInfo -and -not $Force) {
return $script:CachedScaleInfo
}
$screen = [System.Windows.Forms.Screen]::PrimaryScreen
# Calculate base DPI scaling
$dpiX = $screen.Bounds.Width / [System.Windows.Forms.SystemInformation]::PrimaryMonitorSize.Width
$dpiY = $screen.Bounds.Height / [System.Windows.Forms.SystemInformation]::PrimaryMonitorSize.Height
# Use the larger of the two scaling factors, with a minimum of 1.0
$baseFactor = [Math]::Max([Math]::Max($dpiX, $dpiY), 1.0)
# Apply resolution-specific additional scaling
$additionalScale = 1.0
$resolutionName = "Unknown"
$resolutionCategory = "Unknown"
if ($screen.Bounds.Width -ge 7680) {
$additionalScale = 2.5
$resolutionName = "8K UHD (7680x4320)"
$resolutionCategory = "8K"
}
elseif ($screen.Bounds.Width -ge 5120) {
$additionalScale = 1.8
$resolutionName = "5K (5120x2880)"
$resolutionCategory = "5K"
}
elseif ($screen.Bounds.Width -ge 3840) {
$additionalScale = 1.5
$resolutionName = "4K UHD (3840x2160)"
$resolutionCategory = "4K"
}
elseif ($screen.Bounds.Width -ge 3440) {
$additionalScale = 1.3
$resolutionName = "UWQHD (3440x1440)"
$resolutionCategory = "UWQHD"
}
elseif ($screen.Bounds.Width -ge 2560) {
$additionalScale = 1.3
$resolutionName = "QHD (2560x1440)"
$resolutionCategory = "QHD"
}
elseif ($screen.Bounds.Width -ge 1920) {
$additionalScale = 1.2
$resolutionName = "FHD (1920x1080)"
$resolutionCategory = "FHD"
}
elseif ($screen.Bounds.Width -ge 1366) {
$additionalScale = 1.0
$resolutionName = "WXGA (1366x768)"
$resolutionCategory = "WXGA"
}
elseif ($screen.Bounds.Width -ge 1280) {
$additionalScale = 1.0
$resolutionName = "HD (1280x720)"
$resolutionCategory = "HD"
}
elseif ($screen.Bounds.Width -ge 1024) {
$additionalScale = 1.0
$resolutionName = "XGA (1024x768)"
$resolutionCategory = "XGA"
}
elseif ($screen.Bounds.Width -ge 800) {
$additionalScale = 0.9
$resolutionName = "SVGA (800x600)"
$resolutionCategory = "SVGA"
}
else {
$additionalScale = 0.8
$resolutionName = "VGA (640x480)"
$resolutionCategory = "VGA"
}
$scaleFactor = $baseFactor * $additionalScale
# Cache the result
$script:CachedScaleInfo = [PSCustomObject]@{
BaseFactor = $baseFactor
AdditionalScale = $additionalScale
TotalScale = $scaleFactor
ScreenWidth = $screen.Bounds.Width
ScreenHeight = $screen.Bounds.Height
DpiX = $dpiX
DpiY = $dpiY
ResolutionName = $resolutionName
ResolutionCategory = $resolutionCategory
}
return $script:CachedScaleInfo
}
function Get-ResponsiveBaseDimensions {
<#
.SYNOPSIS
Returns standard base dimensions for responsive GUI design.
.DESCRIPTION
Provides a hashtable of standard base dimensions that should be scaled
according to screen resolution. These are the recommended defaults.
.PARAMETER CustomDimensions
Optional hashtable to override default dimensions.
.OUTPUTS
Hashtable with base dimensions for GUI elements.
.EXAMPLE
$dims = Get-ResponsiveBaseDimensions
$scaledMargin = [int]($dims.Margin * $scaleFactor)
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $false)]
[hashtable]$CustomDimensions = @{}
)
# Default base dimensions (before scaling)
$defaultDimensions = @{
# Form dimensions
FormWidth = 800
FormHeight = 600
MinFormWidth = 600
MinFormHeight = 450
# Font sizes - Microsoft Professional Standards (Segoe UI 9pt)
BaseFontSize = 9
MinFontSize = 8
TitleFontSize = 10
HeaderFontSize = 9
LabelFontSize = 8 # 1pt smaller than controls for better visual hierarchy
# Margins and spacing - Microsoft Standards
Margin = 12
Spacing = 6
SmallSpacing = 4
LargeSpacing = 12
# Control dimensions - Microsoft Professional Standards
ControlHeight = 20
ButtonHeight = 23
ButtonWidth = 75
TextBoxHeight = 20
LabelHeight = 20 # Match textbox height for vertical alignment
# Layout
LabelWidth = 140
InputWidth = 250
TabMargin = 8
# Specific controls
ProgressBarHeight = 16
CheckBoxHeight = 20
NumericUpDownHeight = 20
ComboBoxHeight = 21
}
# Merge custom dimensions with defaults
foreach ($key in $CustomDimensions.Keys) {
$defaultDimensions[$key] = $CustomDimensions[$key]
}
return $defaultDimensions
}
function Get-ResponsiveScaledValue {
<#
.SYNOPSIS
Scales a value based on the current DPI scale factor.
.DESCRIPTION
Applies the DPI scale factor to a base value and returns the scaled integer value.
Optionally enforces minimum and maximum values.
.PARAMETER BaseValue
The base value to scale (before DPI scaling).
.PARAMETER ScaleFactor
The scale factor to apply. If not provided, uses cached scale info.
.PARAMETER MinValue
Optional minimum value to enforce.
.PARAMETER MaxValue
Optional maximum value to enforce.
.OUTPUTS
Integer scaled value.
.EXAMPLE
$scaledWidth = Get-ResponsiveScaledValue -BaseValue 800 -MinValue 600
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[int]$BaseValue,
[Parameter(Mandatory = $false)]
[double]$ScaleFactor,
[Parameter(Mandatory = $false)]
[int]$MinValue,
[Parameter(Mandatory = $false)]
[int]$MaxValue
)
# Get scale factor if not provided
if (-not $ScaleFactor) {
$scaleInfo = Get-ResponsiveDPIScale
$ScaleFactor = $scaleInfo.TotalScale
}
# Calculate scaled value
$scaledValue = [int]($BaseValue * $ScaleFactor)
# Apply min/max constraints
if ($MinValue -and $scaledValue -lt $MinValue) {
$scaledValue = $MinValue
}
if ($MaxValue -and $scaledValue -gt $MaxValue) {
$scaledValue = $MaxValue
}
return $scaledValue
}
#endregion
#region Responsive Control Creation Functions
function New-ResponsiveForm {
<#
.SYNOPSIS
Creates a responsive Windows Form with automatic DPI scaling.
.DESCRIPTION
Creates a new Windows Form with responsive sizing based on screen resolution.
Automatically applies DPI scaling and sets appropriate minimum sizes.
.PARAMETER Title
The title of the form window.
.PARAMETER Width
Base width of the form (before scaling).
.PARAMETER Height
Base height of the form (before scaling).
.PARAMETER MinWidth
Minimum width of the form. Default: 600
.PARAMETER MinHeight
Minimum height of the form. Default: 450
.PARAMETER StartPosition
Form start position. Default: CenterScreen
.PARAMETER Resizable
Whether the form is resizable. Default: $false
.OUTPUTS
System.Windows.Forms.Form object with responsive settings applied.
.EXAMPLE
$form = New-ResponsiveForm -Title "My Application" -Width 800 -Height 600
$form.ShowDialog()
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$Title,
[Parameter(Mandatory = $false)]
[int]$Width = 800,
[Parameter(Mandatory = $false)]
[int]$Height = 600,
[Parameter(Mandatory = $false)]
[int]$MinWidth = 600,
[Parameter(Mandatory = $false)]
[int]$MinHeight = 450,
[Parameter(Mandatory = $false)]
[string]$StartPosition = 'CenterScreen',
[Parameter(Mandatory = $false)]
[bool]$Resizable = $false
)
$scaleInfo = Get-ResponsiveDPIScale
$scaleFactor = $scaleInfo.TotalScale
# Calculate scaled dimensions
$scaledWidth = Get-ResponsiveScaledValue -BaseValue $Width -MinValue $MinWidth
$scaledHeight = Get-ResponsiveScaledValue -BaseValue $Height -MinValue $MinHeight
# Create form
$form = New-Object System.Windows.Forms.Form
$form.Text = $Title
$form.Size = New-Object System.Drawing.Size($scaledWidth, $scaledHeight)
$form.MinimumSize = New-Object System.Drawing.Size($MinWidth, $MinHeight)
$form.StartPosition = $StartPosition
$form.AutoScaleMode = [System.Windows.Forms.AutoScaleMode]::Dpi
$form.AutoScaleDimensions = New-Object System.Drawing.SizeF(96, 96)
# Set form border style based on resizable parameter
if ($Resizable) {
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::Sizable
$form.MaximizeBox = $true
}
else {
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$form.MaximizeBox = $false
}
$form.MinimizeBox = $true
# Set default font
$baseDims = Get-ResponsiveBaseDimensions
$fontSize = Get-ResponsiveScaledValue -BaseValue $baseDims.BaseFontSize -MinValue $baseDims.MinFontSize
$form.Font = New-Object System.Drawing.Font("Segoe UI", $fontSize, [System.Drawing.FontStyle]::Regular)
# Store scale info in form Tag for later use
$form.Tag = @{
ScaleInfo = $scaleInfo
ScaleFactor = $scaleFactor
BaseDimensions = $baseDims
}
return $form
}
function New-ResponsivePoint {
<#
.SYNOPSIS
Safely construct a System.Drawing.Point from X/Y values, guarding against
unexpected argument expansion issues (e.g., 4-arg constructor errors).
.DESCRIPTION
Handles both standard call style New-ResponsivePoint $x $y and the
array-style call New-ResponsivePoint($x, $y) by unpacking the array
PowerShell creates for the arguments.
#>
param(
[Parameter(Position = 0)]
[object]$X,
[Parameter(Position = 1)]
[object]$Y
)
# Flatten potential arrays and coerce to integers so that only two
# well-defined values are ever passed to the Point constructor.
$rawX = $X
$rawY = $Y
# If called as New-ResponsivePoint($x, $y), PowerShell passes a single
# array argument. When Y is not explicitly provided, unpack X into X/Y.
if ($null -eq $Y -and $X -is [System.Array] -and $X.Count -ge 2) {
$Y = $X[1]
$X = $X[0]
}
if ($X -is [System.Array] -and $X.Count -gt 0) { $X = $X[0] }
if ($Y -is [System.Array] -and $Y.Count -gt 0) { $Y = $Y[0] }
try {
$intX = [int]$X
$intY = [int]$Y
return New-Object System.Drawing.Point($intX, $intY)
}
catch {
$message = "New-ResponsivePoint failed to construct System.Drawing.Point. RawX='$rawX', RawY='$rawY', X='$X', Y='$Y'. Error: $($_.Exception.Message)"
$writeLog = Get-Command -Name Write-Log -ErrorAction SilentlyContinue
if ($writeLog) {
& $writeLog -Message $message -Level ERROR
}
else {
Write-Warning $message
}
throw
}
}
function New-ResponsiveLabel {
<#
.SYNOPSIS
Creates a responsive Label control with modern styling.
.PARAMETER Text
The text to display in the label.
.PARAMETER X
Base X position (before scaling).
.PARAMETER Y
Base Y position (before scaling).
.PARAMETER Width
Base width (before scaling). Default: 150
.PARAMETER Height
Base height (before scaling). Default: 30 (increased for better text display)
.PARAMETER ScaleFactor
Optional scale factor. If not provided, uses cached value.
.OUTPUTS
System.Windows.Forms.Label object with modern styling applied.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$Text,
[Parameter(Mandatory = $true)]
[int]$X,
[Parameter(Mandatory = $true)]
[int]$Y,
[Parameter(Mandatory = $false)]
[int]$Width = 150,
[Parameter(Mandatory = $false)]
[int]$Height = 50,
[Parameter(Mandatory = $false)]
[double]$ScaleFactor
)
if (-not $ScaleFactor) {
$scaleInfo = Get-ResponsiveDPIScale
$ScaleFactor = $scaleInfo.TotalScale
}
# Get base dimensions for font sizing - Use LabelFontSize for labels
$baseDims = Get-ResponsiveBaseDimensions
$fontSize = Get-ResponsiveScaledValue -BaseValue $baseDims.LabelFontSize -MinValue $baseDims.MinFontSize
$label = New-Object System.Windows.Forms.Label
$label.Text = $Text
$label.Location = New-ResponsivePoint(
(Get-ResponsiveScaledValue -BaseValue $X -ScaleFactor $ScaleFactor),
(Get-ResponsiveScaledValue -BaseValue $Y -ScaleFactor $ScaleFactor)
)
$label.Size = New-Object System.Drawing.Size(
(Get-ResponsiveScaledValue -BaseValue $Width -ScaleFactor $ScaleFactor),
(Get-ResponsiveScaledValue -BaseValue $Height -ScaleFactor $ScaleFactor)
)
$label.AutoSize = $false
$label.Font = New-Object System.Drawing.Font("Segoe UI", $fontSize, [System.Drawing.FontStyle]::Regular)
$label.TextAlign = [System.Drawing.ContentAlignment]::MiddleLeft
return $label
}
function New-ResponsiveTextBox {
<#
.SYNOPSIS
Creates a responsive TextBox control with modern styling.
.PARAMETER X
Base X position (before scaling).
.PARAMETER Y
Base Y position (before scaling).
.PARAMETER Width
Base width (before scaling). Default: 250
.PARAMETER Height
Base height (before scaling). Default: 30 (increased for better text display)
.PARAMETER Text
Initial text value.
.PARAMETER Multiline
Whether the textbox is multiline. Default: $false
.PARAMETER ScaleFactor
Optional scale factor. If not provided, uses cached value.
.OUTPUTS
System.Windows.Forms.TextBox object with modern styling applied.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[int]$X,
[Parameter(Mandatory = $true)]
[int]$Y,
[Parameter(Mandatory = $false)]
[int]$Width = 250,
[Parameter(Mandatory = $false)]
[int]$Height = 50,
[Parameter(Mandatory = $false)]
[string]$Text = '',
[Parameter(Mandatory = $false)]
[bool]$Multiline = $false,
[Parameter(Mandatory = $false)]
[double]$ScaleFactor
)
if (-not $ScaleFactor) {
$scaleInfo = Get-ResponsiveDPIScale
$ScaleFactor = $scaleInfo.TotalScale
}
# Get base dimensions for font sizing
$baseDims = Get-ResponsiveBaseDimensions
$fontSize = Get-ResponsiveScaledValue -BaseValue $baseDims.BaseFontSize -MinValue $baseDims.MinFontSize
$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Text = $Text
$textBox.Multiline = $Multiline
$textBox.Location = New-ResponsivePoint(
(Get-ResponsiveScaledValue -BaseValue $X -ScaleFactor $ScaleFactor),
(Get-ResponsiveScaledValue -BaseValue $Y -ScaleFactor $ScaleFactor)
)
$textBox.Size = New-Object System.Drawing.Size(
(Get-ResponsiveScaledValue -BaseValue $Width -ScaleFactor $ScaleFactor),
(Get-ResponsiveScaledValue -BaseValue $Height -ScaleFactor $ScaleFactor)
)
$textBox.Font = New-Object System.Drawing.Font("Segoe UI", $fontSize, [System.Drawing.FontStyle]::Regular)
return $textBox
}
function New-ResponsiveButton {
<#
.SYNOPSIS
Creates a responsive Button control with modern flat styling.
.PARAMETER Text
The text to display on the button.
.PARAMETER X
Base X position (before scaling).
.PARAMETER Y
Base Y position (before scaling).
.PARAMETER Width
Base width (before scaling). Default: 100
.PARAMETER Height
Base height (before scaling). Default: 60 (increased for better text display with larger fonts)
.PARAMETER ScaleFactor
Optional scale factor. If not provided, uses cached value.
.OUTPUTS
System.Windows.Forms.Button object with modern flat styling applied.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$Text,
[Parameter(Mandatory = $true)]
[int]$X,
[Parameter(Mandatory = $true)]
[int]$Y,
[Parameter(Mandatory = $false)]
[int]$Width = 100,
[Parameter(Mandatory = $false)]
[int]$Height = 60,
[Parameter(Mandatory = $false)]
[double]$ScaleFactor
)
if (-not $ScaleFactor) {
$scaleInfo = Get-ResponsiveDPIScale
$ScaleFactor = $scaleInfo.TotalScale
}
# Get base dimensions for font sizing
$baseDims = Get-ResponsiveBaseDimensions
$fontSize = Get-ResponsiveScaledValue -BaseValue $baseDims.BaseFontSize -MinValue $baseDims.MinFontSize
$button = New-Object System.Windows.Forms.Button
$button.Text = $Text
$button.Location = New-ResponsivePoint(
(Get-ResponsiveScaledValue -BaseValue $X -ScaleFactor $ScaleFactor),
(Get-ResponsiveScaledValue -BaseValue $Y -ScaleFactor $ScaleFactor)
)
$button.Size = New-Object System.Drawing.Size(
(Get-ResponsiveScaledValue -BaseValue $Width -ScaleFactor $ScaleFactor),
(Get-ResponsiveScaledValue -BaseValue $Height -ScaleFactor $ScaleFactor)
)
$button.Font = New-Object System.Drawing.Font("Segoe UI", $fontSize, [System.Drawing.FontStyle]::Regular)
$button.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
$button.FlatAppearance.BorderSize = 1
$button.FlatAppearance.BorderColor = [System.Drawing.Color]::FromArgb(200, 200, 200)
$button.UseVisualStyleBackColor = $true
return $button
}
function New-ResponsiveCheckBox {
<#
.SYNOPSIS
Creates a responsive CheckBox control with modern flat styling.
.PARAMETER Text
The text to display next to the checkbox.
.PARAMETER X
Base X position (before scaling).
.PARAMETER Y
Base Y position (before scaling).
.PARAMETER Width
Base width (before scaling). Default: 200
.PARAMETER Height
Base height (before scaling). Default: 30 (increased for better text display)
.PARAMETER Checked
Initial checked state. Default: $false
.PARAMETER ScaleFactor
Optional scale factor. If not provided, uses cached value.
.OUTPUTS
System.Windows.Forms.CheckBox object with modern flat styling applied.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$Text,
[Parameter(Mandatory = $true)]
[int]$X,
[Parameter(Mandatory = $true)]
[int]$Y,
[Parameter(Mandatory = $false)]
[int]$Width = 200,
[Parameter(Mandatory = $false)]
[int]$Height = 50,
[Parameter(Mandatory = $false)]
[bool]$Checked = $false,
[Parameter(Mandatory = $false)]
[double]$ScaleFactor
)
if (-not $ScaleFactor) {
$scaleInfo = Get-ResponsiveDPIScale
$ScaleFactor = $scaleInfo.TotalScale
}
# Get base dimensions for font sizing
$baseDims = Get-ResponsiveBaseDimensions
$fontSize = Get-ResponsiveScaledValue -BaseValue $baseDims.BaseFontSize -MinValue $baseDims.MinFontSize
$checkBox = New-Object System.Windows.Forms.CheckBox
$checkBox.Text = $Text
$checkBox.Checked = $Checked
$checkBox.Location = New-ResponsivePoint(
(Get-ResponsiveScaledValue -BaseValue $X -ScaleFactor $ScaleFactor),
(Get-ResponsiveScaledValue -BaseValue $Y -ScaleFactor $ScaleFactor)
)
$checkBox.Size = New-Object System.Drawing.Size(
(Get-ResponsiveScaledValue -BaseValue $Width -ScaleFactor $ScaleFactor),
(Get-ResponsiveScaledValue -BaseValue $Height -ScaleFactor $ScaleFactor)
)
$checkBox.Font = New-Object System.Drawing.Font("Segoe UI", $fontSize, [System.Drawing.FontStyle]::Regular)
$checkBox.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
$checkBox.UseVisualStyleBackColor = $true
return $checkBox
}
function New-ResponsiveComboBox {
<#
.SYNOPSIS
Creates a responsive ComboBox control.
.PARAMETER X
Base X position (before scaling).
.PARAMETER Y
Base Y position (before scaling).
.PARAMETER Width
Base width (before scaling). Default: 200
.PARAMETER Height
Base height (before scaling). Default: 25
.PARAMETER Items
Array of items to add to the combobox.
.PARAMETER SelectedIndex
Initial selected index. Default: -1 (none selected)
.PARAMETER ScaleFactor
Optional scale factor. If not provided, uses cached value.
.OUTPUTS
System.Windows.Forms.ComboBox object.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[int]$X,
[Parameter(Mandatory = $true)]
[int]$Y,
[Parameter(Mandatory = $false)]
[int]$Width = 200,
[Parameter(Mandatory = $false)]
[int]$Height = 25,
[Parameter(Mandatory = $false)]
[array]$Items = @(),
[Parameter(Mandatory = $false)]
[int]$SelectedIndex = -1,
[Parameter(Mandatory = $false)]
[double]$ScaleFactor
)
if (-not $ScaleFactor) {
$scaleInfo = Get-ResponsiveDPIScale
$ScaleFactor = $scaleInfo.TotalScale
}
$comboBox = New-Object System.Windows.Forms.ComboBox
$comboBox.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$comboBox.Location = New-ResponsivePoint(
(Get-ResponsiveScaledValue -BaseValue $X -ScaleFactor $ScaleFactor),
(Get-ResponsiveScaledValue -BaseValue $Y -ScaleFactor $ScaleFactor)
)
$comboBox.Size = New-Object System.Drawing.Size(
(Get-ResponsiveScaledValue -BaseValue $Width -ScaleFactor $ScaleFactor),
(Get-ResponsiveScaledValue -BaseValue $Height -ScaleFactor $ScaleFactor)
)
if ($Items.Count -gt 0) {
$comboBox.Items.AddRange($Items)
}
if ($SelectedIndex -ge 0 -and $SelectedIndex -lt $comboBox.Items.Count) {
$comboBox.SelectedIndex = $SelectedIndex
}
return $comboBox
}
function New-ResponsiveProgressBar {
<#
.SYNOPSIS
Creates a responsive ProgressBar control.
.PARAMETER X
Base X position (before scaling).
.PARAMETER Y
Base Y position (before scaling).
.PARAMETER Width
Base width (before scaling). Default: 300
.PARAMETER Height
Base height (before scaling). Default: 25
.PARAMETER Value
Initial progress value (0-100). Default: 0
.PARAMETER ScaleFactor
Optional scale factor. If not provided, uses cached value.
.OUTPUTS
System.Windows.Forms.ProgressBar object.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[int]$X,
[Parameter(Mandatory = $true)]
[int]$Y,
[Parameter(Mandatory = $false)]
[int]$Width = 300,
[Parameter(Mandatory = $false)]
[int]$Height = 25,
[Parameter(Mandatory = $false)]
[int]$Value = 0,
[Parameter(Mandatory = $false)]
[double]$ScaleFactor
)
if (-not $ScaleFactor) {
$scaleInfo = Get-ResponsiveDPIScale
$ScaleFactor = $scaleInfo.TotalScale
}
$progressBar = New-Object System.Windows.Forms.ProgressBar
$progressBar.Minimum = 0
$progressBar.Maximum = 100
$progressBar.Value = $Value
$progressBar.Location = New-ResponsivePoint(
(Get-ResponsiveScaledValue -BaseValue $X -ScaleFactor $ScaleFactor),
(Get-ResponsiveScaledValue -BaseValue $Y -ScaleFactor $ScaleFactor)
)
$progressBar.Size = New-Object System.Drawing.Size(
(Get-ResponsiveScaledValue -BaseValue $Width -ScaleFactor $ScaleFactor),
(Get-ResponsiveScaledValue -BaseValue $Height -ScaleFactor $ScaleFactor)
)
return $progressBar
}
function New-ResponsiveNumericUpDown {
<#
.SYNOPSIS
Creates a responsive NumericUpDown control with modern styling.
.PARAMETER X
Base X position (before scaling).
.PARAMETER Y
Base Y position (before scaling).
.PARAMETER Width
Base width (before scaling). Default: 120
.PARAMETER Height
Base height (before scaling). Default: 30 (increased for better text display)
.PARAMETER Minimum
Minimum value. Default: 0
.PARAMETER Maximum
Maximum value. Default: 100
.PARAMETER Value
Initial value. Default: 0
.PARAMETER ScaleFactor
Optional scale factor. If not provided, uses cached value.
.OUTPUTS
System.Windows.Forms.NumericUpDown object with modern styling applied.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[int]$X,
[Parameter(Mandatory = $true)]
[int]$Y,
[Parameter(Mandatory = $false)]
[int]$Width = 120,
[Parameter(Mandatory = $false)]
[int]$Height = 50,
[Parameter(Mandatory = $false)]
[decimal]$Minimum = 0,
[Parameter(Mandatory = $false)]
[decimal]$Maximum = 100,
[Parameter(Mandatory = $false)]
[decimal]$Value = 0,
[Parameter(Mandatory = $false)]
[double]$ScaleFactor
)
if (-not $ScaleFactor) {
$scaleInfo = Get-ResponsiveDPIScale
$ScaleFactor = $scaleInfo.TotalScale
}
# Get base dimensions for font sizing
$baseDims = Get-ResponsiveBaseDimensions
$fontSize = Get-ResponsiveScaledValue -BaseValue $baseDims.BaseFontSize -MinValue $baseDims.MinFontSize
$numericUpDown = New-Object System.Windows.Forms.NumericUpDown
$numericUpDown.Minimum = $Minimum
$numericUpDown.Maximum = $Maximum
$numericUpDown.Value = $Value