wetyukmnbxc

Untitled

Mar 6th, 2023
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # 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.
  2.  
  3. # 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:
  4.  
  5. # powershell
  6. Add-Type -AssemblyName System.Windows.Forms
  7. start-transcript
  8.  
  9. # Create a new form
  10. $form = New-Object System.Windows.Forms.Form
  11. $form.Text = "Numbers"
  12. $form.Size = New-Object System.Drawing.Size(400, 400)
  13. $form.StartPosition = "CenterScreen"
  14.  
  15. # Create 1 TextBox
  16. $textDisplay = New-Object System.Windows.Forms.TextBox
  17. $textDisplay.Location = New-Object System.Drawing.Point(20, 20)
  18. $textDisplay.Size = New-Object System.Drawing.Size(340, 120)
  19. $textDisplay.Font = New-Object System.Drawing.Font("Arial", 50)
  20. $textDisplay.ForeColor = "Green"
  21. $textDisplay.Text = "Press a button to show the number !"
  22.  
  23. # Create 9 buttons
  24. $button1 = New-Object System.Windows.Forms.Button
  25. $button1.Location = New-Object System.Drawing.Point(20, 120)
  26. $button1.Size = New-Object System.Drawing.Size(100, 50)
  27. $button1.Text = "1"
  28. $button1.Font = New-Object System.Drawing.Font("Arial", 15)
  29. $button1.BackColor = "Blue"
  30. $button1.ForeColor = "White"
  31. $button1.Add_Click({
  32.   if ($button1.BackColor-ne "Blue") {
  33.     $button1.BackColor = "Blue"
  34.     $button1.Font = New-Object System.Drawing.Font("Arial", 15)
  35.   } else {
  36.     $button1.BackColor = "Red"
  37.     $button1.Font = New-Object System.Drawing.Font("Arial", 30)
  38.   }
  39.  
  40.   $textDisplay.Text = $button1.Text + " One"
  41.   write-host $textDisplay.Text
  42. })
  43.  
  44. $button2 = New-Object System.Windows.Forms.Button
  45. $button2.Location = New-Object System.Drawing.Point(140, 120)
  46. $button2.Size = New-Object System.Drawing.Size(100, 50)
  47. $button2.Text = "2"
  48. $button2.Font = New-Object System.Drawing.Font("Arial", 15)
  49. $button2.BackColor = "Blue"
  50. $button2.ForeColor = "White"
  51. $button2.Add_Click({
  52.   if ($button2.BackColor-ne "Blue") {
  53.     $button2.BackColor = "Blue"
  54.     $button2.Font = New-Object System.Drawing.Font("Arial", 15)
  55.   } else {
  56.     $button2.BackColor = "Red"
  57.     $button2.Font = New-Object System.Drawing.Font("Arial", 30)
  58.   }
  59.  
  60.   $textDisplay.Text = $button2.Text + " Two"
  61.   write-host $textDisplay.Text
  62. })
  63.  
  64. $button3 = New-Object System.Windows.Forms.Button
  65. $button3.Location = New-Object System.Drawing.Point(260, 120)
  66. $button3.Size = New-Object System.Drawing.Size(100, 50)
  67. $button3.Text = "3"
  68. $button3.Font = New-Object System.Drawing.Font("Arial", 15)
  69. $button3.BackColor = "Blue"
  70. $button3.ForeColor = "White"
  71. $button3.Add_Click({
  72.   if ($button3.BackColor-ne "Blue") {
  73.     $button3.BackColor = "Blue"
  74.     $button3.Font = New-Object System.Drawing.Font("Arial", 15)
  75.   } else {
  76.     $button3.BackColor = "Red"
  77.     $button3.Font = New-Object System.Drawing.Font("Arial", 30)
  78.   }
  79.  
  80.   $textDisplay.Text = $button3.Text + " Three"
  81.   write-host $textDisplay.Text
  82. })
  83.  
  84. $button4 = New-Object System.Windows.Forms.Button
  85. $button4.Location = New-Object System.Drawing.Point(20, 180)
  86. $button4.Size = New-Object System.Drawing.Size(100, 50)
  87. $button4.Text = "4"
  88. $button4.Font = New-Object System.Drawing.Font("Arial", 15)
  89. $button4.BackColor = "Blue"
  90. $button4.ForeColor = "White"
  91. $button4.Add_Click({
  92.   if ($button4.BackColor-ne "Blue") {
  93.     $button4.BackColor = "Blue"
  94.     $button4.Font = New-Object System.Drawing.Font("Arial", 15)
  95.   } else {
  96.     $button4.BackColor = "Red"
  97.     $button4.Font = New-Object System.Drawing.Font("Arial", 30)
  98.   }
  99.  
  100.   $textDisplay.Text = $button4.Text + " Four"
  101.   write-host $textDisplay.Text
  102. })
  103.  
  104. $button5 = New-Object System.Windows.Forms.Button
  105. $button5.Location = New-Object System.Drawing.Point(140, 180)
  106. $button5.Size = New-Object System.Drawing.Size(100, 50)
  107. $button5.Text = "5"
  108. $button5.Font = New-Object System.Drawing.Font("Arial", 15)
  109. $button5.BackColor = "Blue"
  110. $button5.ForeColor = "White"
  111. $button5.Add_Click({
  112.   if ($button5.BackColor-ne "Blue") {
  113.     $button5.BackColor = "Blue"
  114.     $button5.Font = New-Object System.Drawing.Font("Arial", 15)
  115.   } else {
  116.     $button5.BackColor = "Red"
  117.     $button5.Font = New-Object System.Drawing.Font("Arial", 30)
  118.   }
  119.   $textDisplay.Text = $button5.Text + " Five"
  120.   write-host $textDisplay.Text
  121. })
  122.  
  123. $button6 = New-Object System.Windows.Forms.Button
  124. $button6.Location = New-Object System.Drawing.Point(260, 180)
  125. $button6.Size = New-Object System.Drawing.Size(100, 50)
  126. $button6.Text = "6"
  127. $button6.Font = New-Object System.Drawing.Font("Arial", 15)
  128. $button6.BackColor = "Blue"
  129. $button6.ForeColor = "White"
  130. $button6.Add_Click({
  131.   if ($button6.BackColor-ne "Blue") {
  132.     $button6.BackColor = "Blue"
  133.     $button6.Font = New-Object System.Drawing.Font("Arial", 15)
  134.   } else {
  135.     $button6.BackColor = "Red"
  136.     $button6.Font = New-Object System.Drawing.Font("Arial", 30)
  137.   }
  138.  
  139.   $textDisplay.Text = $button6.Text + " Six"
  140.   write-host $textDisplay.Text
  141. })
  142.  
  143. $button7 = New-Object System.Windows.Forms.Button
  144. $button7.Location = New-Object System.Drawing.Point(20, 240)
  145. $button7.Size = New-Object System.Drawing.Size(100, 50)
  146. $button7.Text = "7"
  147. $button7.Font = New-Object System.Drawing.Font("Arial", 15)
  148. $button7.BackColor = "Blue"
  149. $button7.ForeColor = "White"
  150. $button7.Add_Click({
  151.   if ($button7.BackColor-ne "Blue") {
  152.     $button7.BackColor = "Blue"
  153.     $button7.Font = New-Object System.Drawing.Font("Arial", 15)
  154.   } else {
  155.     $button7.BackColor = "Red"
  156.     $button7.Font = New-Object System.Drawing.Font("Arial", 30)
  157.   }
  158.  
  159.   $textDisplay.Text = $button7.Text + " Seven"
  160.   write-host $textDisplay.Text
  161. })
  162.  
  163. $button8 = New-Object System.Windows.Forms.Button
  164. $button8.Location = New-Object System.Drawing.Point(140, 240)
  165. $button8.Size = New-Object System.Drawing.Size(100, 50)
  166. $button8.Text = "8"
  167. $button8.Font = New-Object System.Drawing.Font("Arial", 15)
  168. $button8.BackColor = "Blue"
  169. $button8.ForeColor = "White"
  170. $button8.Add_Click({
  171.   if ($button8.BackColor-ne "Blue") {
  172.     $button8.BackColor = "Blue"
  173.     $button8.Font = New-Object System.Drawing.Font("Arial", 15)
  174.   } else {
  175.     $button8.BackColor = "Red"
  176.     $button8.Font = New-Object System.Drawing.Font("Arial", 30)
  177.   }
  178.   $textDisplay.Text = $button8.Text + " Eight"
  179.   write-host $textDisplay.Text
  180. })
  181.  
  182. $button9 = New-Object System.Windows.Forms.Button
  183. $button9.Location = New-Object System.Drawing.Point(260, 240)
  184. $button9.Size = New-Object System.Drawing.Size(100, 50)
  185. $button9.Text = "9"
  186. $button9.Font = New-Object System.Drawing.Font("Arial", 15)
  187. $button9.BackColor = "Blue"
  188. $button9.ForeColor = "White"
  189. $button9.Add_Click({
  190.   if ($button9.BackColor-ne "Blue") {
  191.     $button9.BackColor = "Blue"
  192.     $button9.Font = New-Object System.Drawing.Font("Arial", 15)
  193.   } else {
  194.     $button9.BackColor = "Red"
  195.     $button9.Font = New-Object System.Drawing.Font("Arial", 30)
  196.   }
  197.   $textDisplay.Text = $button9.Text + " Nine"
  198.   write-host $textDisplay.Text
  199. })
  200.  
  201. $button0 = New-Object System.Windows.Forms.Button
  202. $button0.Location = New-Object System.Drawing.Point(140, 300)
  203. $button0.Size = New-Object System.Drawing.Size(100, 50)
  204. $button0.Text = "0"
  205. $button0.Font = New-Object System.Drawing.Font("Arial", 15)
  206. $button0.BackColor = "Blue"
  207. $button0.ForeColor = "White"
  208. $button0.Add_Click({
  209.   if ($button0.BackColor-ne "Blue") {
  210.     $button0.BackColor = "Blue"
  211.     $button0.Font = New-Object System.Drawing.Font("Arial", 15)
  212.   } else {
  213.     $button0.BackColor = "Red"
  214.     $button0.Font = New-Object System.Drawing.Font("Arial", 30)
  215.   }
  216.   $textDisplay.Text = $button0.Text + " Zero"
  217.   write-host $textDisplay.Text
  218. })
  219.  
  220. # Add buttons to the form
  221. $form.Controls.Add($button1)
  222. $form.Controls.Add($button2)
  223. $form.Controls.Add($button3)
  224. $form.Controls.Add($button4)
  225. $form.Controls.Add($button5)
  226. $form.Controls.Add($button6)
  227. $form.Controls.Add($button7)
  228. $form.Controls.Add($button8)
  229. $form.Controls.Add($button9)
  230. $form.Controls.Add($button0)
  231. $form.Controls.Add($textDisplay)
  232.  
  233. # Show the form
  234. $form.ShowDialog() | Out-Null
Add Comment
Please, Sign In to add comment