Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Write a powershell script to create GUI windows with 9 click blue buttons inside.When click one of the buttons, the button color change from blue to red.
- # Here 's a PowerShell script that creates a GUI window with 9 blue buttons inside. When you click one of the buttons, the button color changes from blue to red:
- # powershell
- Add-Type -AssemblyName System.Windows.Forms
- start-transcript
- # Create a new form
- $form = New-Object System.Windows.Forms.Form
- $form.Text = "Numbers"
- $form.Size = New-Object System.Drawing.Size(400, 400)
- $form.StartPosition = "CenterScreen"
- # Create 1 TextBox
- $textDisplay = New-Object System.Windows.Forms.TextBox
- $textDisplay.Location = New-Object System.Drawing.Point(20, 20)
- $textDisplay.Size = New-Object System.Drawing.Size(340, 120)
- $textDisplay.Font = New-Object System.Drawing.Font("Arial", 50)
- $textDisplay.ForeColor = "Green"
- $textDisplay.Text = "Press a button to show the number !"
- # Create 9 buttons
- $button1 = New-Object System.Windows.Forms.Button
- $button1.Location = New-Object System.Drawing.Point(20, 120)
- $button1.Size = New-Object System.Drawing.Size(100, 50)
- $button1.Text = "1"
- $button1.Font = New-Object System.Drawing.Font("Arial", 15)
- $button1.BackColor = "Blue"
- $button1.ForeColor = "White"
- $button1.Add_Click({
- if ($button1.BackColor-ne "Blue") {
- $button1.BackColor = "Blue"
- $button1.Font = New-Object System.Drawing.Font("Arial", 15)
- } else {
- $button1.BackColor = "Red"
- $button1.Font = New-Object System.Drawing.Font("Arial", 30)
- }
- $textDisplay.Text = $button1.Text + " One"
- write-host $textDisplay.Text
- })
- $button2 = New-Object System.Windows.Forms.Button
- $button2.Location = New-Object System.Drawing.Point(140, 120)
- $button2.Size = New-Object System.Drawing.Size(100, 50)
- $button2.Text = "2"
- $button2.Font = New-Object System.Drawing.Font("Arial", 15)
- $button2.BackColor = "Blue"
- $button2.ForeColor = "White"
- $button2.Add_Click({
- if ($button2.BackColor-ne "Blue") {
- $button2.BackColor = "Blue"
- $button2.Font = New-Object System.Drawing.Font("Arial", 15)
- } else {
- $button2.BackColor = "Red"
- $button2.Font = New-Object System.Drawing.Font("Arial", 30)
- }
- $textDisplay.Text = $button2.Text + " Two"
- write-host $textDisplay.Text
- })
- $button3 = New-Object System.Windows.Forms.Button
- $button3.Location = New-Object System.Drawing.Point(260, 120)
- $button3.Size = New-Object System.Drawing.Size(100, 50)
- $button3.Text = "3"
- $button3.Font = New-Object System.Drawing.Font("Arial", 15)
- $button3.BackColor = "Blue"
- $button3.ForeColor = "White"
- $button3.Add_Click({
- if ($button3.BackColor-ne "Blue") {
- $button3.BackColor = "Blue"
- $button3.Font = New-Object System.Drawing.Font("Arial", 15)
- } else {
- $button3.BackColor = "Red"
- $button3.Font = New-Object System.Drawing.Font("Arial", 30)
- }
- $textDisplay.Text = $button3.Text + " Three"
- write-host $textDisplay.Text
- })
- $button4 = New-Object System.Windows.Forms.Button
- $button4.Location = New-Object System.Drawing.Point(20, 180)
- $button4.Size = New-Object System.Drawing.Size(100, 50)
- $button4.Text = "4"
- $button4.Font = New-Object System.Drawing.Font("Arial", 15)
- $button4.BackColor = "Blue"
- $button4.ForeColor = "White"
- $button4.Add_Click({
- if ($button4.BackColor-ne "Blue") {
- $button4.BackColor = "Blue"
- $button4.Font = New-Object System.Drawing.Font("Arial", 15)
- } else {
- $button4.BackColor = "Red"
- $button4.Font = New-Object System.Drawing.Font("Arial", 30)
- }
- $textDisplay.Text = $button4.Text + " Four"
- write-host $textDisplay.Text
- })
- $button5 = New-Object System.Windows.Forms.Button
- $button5.Location = New-Object System.Drawing.Point(140, 180)
- $button5.Size = New-Object System.Drawing.Size(100, 50)
- $button5.Text = "5"
- $button5.Font = New-Object System.Drawing.Font("Arial", 15)
- $button5.BackColor = "Blue"
- $button5.ForeColor = "White"
- $button5.Add_Click({
- if ($button5.BackColor-ne "Blue") {
- $button5.BackColor = "Blue"
- $button5.Font = New-Object System.Drawing.Font("Arial", 15)
- } else {
- $button5.BackColor = "Red"
- $button5.Font = New-Object System.Drawing.Font("Arial", 30)
- }
- $textDisplay.Text = $button5.Text + " Five"
- write-host $textDisplay.Text
- })
- $button6 = New-Object System.Windows.Forms.Button
- $button6.Location = New-Object System.Drawing.Point(260, 180)
- $button6.Size = New-Object System.Drawing.Size(100, 50)
- $button6.Text = "6"
- $button6.Font = New-Object System.Drawing.Font("Arial", 15)
- $button6.BackColor = "Blue"
- $button6.ForeColor = "White"
- $button6.Add_Click({
- if ($button6.BackColor-ne "Blue") {
- $button6.BackColor = "Blue"
- $button6.Font = New-Object System.Drawing.Font("Arial", 15)
- } else {
- $button6.BackColor = "Red"
- $button6.Font = New-Object System.Drawing.Font("Arial", 30)
- }
- $textDisplay.Text = $button6.Text + " Six"
- write-host $textDisplay.Text
- })
- $button7 = New-Object System.Windows.Forms.Button
- $button7.Location = New-Object System.Drawing.Point(20, 240)
- $button7.Size = New-Object System.Drawing.Size(100, 50)
- $button7.Text = "7"
- $button7.Font = New-Object System.Drawing.Font("Arial", 15)
- $button7.BackColor = "Blue"
- $button7.ForeColor = "White"
- $button7.Add_Click({
- if ($button7.BackColor-ne "Blue") {
- $button7.BackColor = "Blue"
- $button7.Font = New-Object System.Drawing.Font("Arial", 15)
- } else {
- $button7.BackColor = "Red"
- $button7.Font = New-Object System.Drawing.Font("Arial", 30)
- }
- $textDisplay.Text = $button7.Text + " Seven"
- write-host $textDisplay.Text
- })
- $button8 = New-Object System.Windows.Forms.Button
- $button8.Location = New-Object System.Drawing.Point(140, 240)
- $button8.Size = New-Object System.Drawing.Size(100, 50)
- $button8.Text = "8"
- $button8.Font = New-Object System.Drawing.Font("Arial", 15)
- $button8.BackColor = "Blue"
- $button8.ForeColor = "White"
- $button8.Add_Click({
- if ($button8.BackColor-ne "Blue") {
- $button8.BackColor = "Blue"
- $button8.Font = New-Object System.Drawing.Font("Arial", 15)
- } else {
- $button8.BackColor = "Red"
- $button8.Font = New-Object System.Drawing.Font("Arial", 30)
- }
- $textDisplay.Text = $button8.Text + " Eight"
- write-host $textDisplay.Text
- })
- $button9 = New-Object System.Windows.Forms.Button
- $button9.Location = New-Object System.Drawing.Point(260, 240)
- $button9.Size = New-Object System.Drawing.Size(100, 50)
- $button9.Text = "9"
- $button9.Font = New-Object System.Drawing.Font("Arial", 15)
- $button9.BackColor = "Blue"
- $button9.ForeColor = "White"
- $button9.Add_Click({
- if ($button9.BackColor-ne "Blue") {
- $button9.BackColor = "Blue"
- $button9.Font = New-Object System.Drawing.Font("Arial", 15)
- } else {
- $button9.BackColor = "Red"
- $button9.Font = New-Object System.Drawing.Font("Arial", 30)
- }
- $textDisplay.Text = $button9.Text + " Nine"
- write-host $textDisplay.Text
- })
- $button0 = New-Object System.Windows.Forms.Button
- $button0.Location = New-Object System.Drawing.Point(140, 300)
- $button0.Size = New-Object System.Drawing.Size(100, 50)
- $button0.Text = "0"
- $button0.Font = New-Object System.Drawing.Font("Arial", 15)
- $button0.BackColor = "Blue"
- $button0.ForeColor = "White"
- $button0.Add_Click({
- if ($button0.BackColor-ne "Blue") {
- $button0.BackColor = "Blue"
- $button0.Font = New-Object System.Drawing.Font("Arial", 15)
- } else {
- $button0.BackColor = "Red"
- $button0.Font = New-Object System.Drawing.Font("Arial", 30)
- }
- $textDisplay.Text = $button0.Text + " Zero"
- write-host $textDisplay.Text
- })
- # Add buttons to the form
- $form.Controls.Add($button1)
- $form.Controls.Add($button2)
- $form.Controls.Add($button3)
- $form.Controls.Add($button4)
- $form.Controls.Add($button5)
- $form.Controls.Add($button6)
- $form.Controls.Add($button7)
- $form.Controls.Add($button8)
- $form.Controls.Add($button9)
- $form.Controls.Add($button0)
- $form.Controls.Add($textDisplay)
- # Show the form
- $form.ShowDialog() | Out-Null
Add Comment
Please, Sign In to add comment