Public/Set-WFForm.ps1
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 |
function Set-WFForm { <# .SYNOPSIS The Set-WFForm function is used to change the properties of a Form or to intract with it .DESCRIPTION The Set-WFForm function is used to change the properties of a Form or to intract with it .PARAMETER Form Specifies the Form control .PARAMETER Text Specifies the text/Title of the form .PARAMETER WindowState Set the Window State of the form. .PARAMETER BringToFront Bring the form to the front of the screen .EXAMPLE PS C:\> Set-WFForm -Form $form1 -BringToFront .EXAMPLE PS C:\> Set-WFForm -Form $form1 -Text "My GUI" .EXAMPLE PS C:\> Set-WFForm -Form $form1 -WindowState "Minimized" .NOTES Author: Francois-Xavier Cat Twitter:@LazyWinAdm www.lazywinadmin.com github.com/lazywinadmin #> [CmdletBinding(SupportsShouldProcess = $true)] param ( [System.Windows.Forms.Form]$Form, [Alias('Title')] [String]$Text = "Hello World", [ValidateSet('Maximized', 'Minimized', 'Normal')] [String]$WindowState, [Switch]$BringToFront ) BEGIN { Add-Type -AssemblyName System.Windows.Forms } PROCESS { IF ($PSBoundParameters["Text"]) { IF ($PSCmdlet.ShouldProcess($Form, "Set the Title")) { $Form.Text = $Text } } IF ($PSBoundParameters["WindowState"]) { IF ($PSCmdlet.ShouldProcess($Form, "Set Windows State to $WindowState")) { $Form.WindowState = $WindowState } } IF ($PSBoundParameters["BringToFront"]) { IF ($PSCmdlet.ShouldProcess($Form, "Bring the Form to the front of the screen")) { $Form.BringToFront() } } } #PROCESS } |