PowerShell script that creates a simple Windows Form with a label and a button:

 PowerShell script that creates a simple Windows Form with a label and a button:


# Load the System.Windows.Forms assembly [void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') # Create the form $form = New-Object System.Windows.Forms.Form $form.Size = New-Object System.Drawing.Size(300, 200) $form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen # Create the label $label = New-Object System.Windows.Forms.Label $label.Text = "Hello, World!" $label.Size = New-Object System.Drawing.Size(100, 20) $label.Location = New-Object System.Drawing.Point(100, 50) $form.Controls.Add($label) # Create the button $button = New-Object System.Windows.Forms.Button $button.Text = "Click Me" $button.Size = New-Object System.Drawing.Size(75, 23) $button.Location = New-Object System.Drawing.Point(100, 100) $button.Add_Click({$label.Text = "Button was clicked"}) $form.Controls.Add($button) # Show the form $form.ShowDialog()

This script uses the System.Windows.Forms assembly to create a form, a label, and a button. The form, label, and button objects are created using the New-Object cmdlet and various properties are set to customize their appearance and behavior. The label text is set to "Hello, World!", and the button text is set to "Click Me". The button's Click event is handled by a script block that changes the label text to "Button was clicked". The form is displayed using the ShowDialog method.

No comments:

Post a Comment