PowerShell script that creates a simple Windows Form

 Here's a PowerShell script that creates a simple Windows Form generator:

Add-Type -AssemblyName System.Windows.Forms $form = New-Object System.Windows.Forms.Form $form.Size = New-Object System.Drawing.Size(300,200) $form.Text = "Windows Form Generator" $label = New-Object System.Windows.Forms.Label $label.Location = New-Object System.Drawing.Point(10,10) $label.Size = New-Object System.Drawing.Size(100,20) $label.Text = "Enter Text:" $form.Controls.Add($label) $textbox = New-Object System.Windows.Forms.TextBox $textbox.Location = New-Object System.Drawing.Point(110,10) $textbox.Size = New-Object System.Drawing.Size(150,20) $form.Controls.Add($textbox) $button = New-Object System.Windows.Forms.Button $button.Location = New-Object System.Drawing.Point(110,50) $button.Size = New-Object System.Drawing.Size(75,23) $button.Text = "Submit" $button.Add_Click({ $form.Controls.Remove($label) $form.Controls.Remove($textbox) $form.Controls.Remove($button) $label = New-Object System.Windows.Forms.Label $label.Location = New-Object System.Drawing.Point(10,10) $label.Size = New-Object System.Drawing.Size(250,20) $label.Text = "You entered: " + $textbox.Text $form.Controls.Add($label) }) $form.Controls.Add($button) $form.ShowDialog()

This script creates a form with a label, textbox, and a submit button. 

When the button is clicked, it removes the label, textbox, and button from the form, 

and replaces it with a new label that displays the text entered in the textbox.


No comments:

Post a Comment