wetyukmnbxc

qqqqq

Mar 11th, 2023 (edited)
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # *********************************************************************
  2.  
  3. # 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.
  4.  
  5. # 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:
  6.  
  7. # powershell
  8. Add-Type -AssemblyName System.Windows.Forms
  9. start-transcript
  10.  
  11. # Create a new form
  12. $form = New-Object System.Windows.Forms.Form
  13. $form.Text = "Numbers"
  14. $form.Size = New-Object System.Drawing.Size(1280,1024)
  15. $form.StartPosition = "CenterScreen"
  16.  
  17. # Create 1 TextBox
  18. $textDisplay = New-Object System.Windows.Forms.TextBox
  19. $textDisplay.Location = New-Object System.Drawing.Point(10, 10)
  20. $textDisplay.AutoSize = 0
  21. $textDisplay.Multiline = 1
  22. $textDisplay.WordWrap = 0
  23. $textDisplay.width = 1400
  24. $textDisplay.height = 400
  25. $textDisplay.Font = New-Object System.Drawing.Font("Arial", 150)
  26. $textDisplay.ForeColor = "Green"
  27. $textDisplay.Text = "Press clear."
  28.  
  29. # Create 9 buttons
  30.  
  31. # button 1
  32. $button1 = New-Object System.Windows.Forms.Button
  33. $button1.Location = New-Object System.Drawing.Point(10, 520)
  34. $button1.Size = New-Object System.Drawing.Size(100, 50)
  35. $button1.Text = "1"
  36. $button1.Font = New-Object System.Drawing.Font("Arial", 15)
  37. $button1.BackColor = "Blue"
  38. $button1.ForeColor = "White"
  39. $button1.Add_Click({
  40.   if ($button1.BackColor-ne "Blue") {
  41.     $button1.BackColor = "Blue"
  42.     $button1.Font = New-Object System.Drawing.Font("Arial", 15)
  43.   } else {
  44.     $button1.BackColor = "Red"
  45.     $button1.Font = New-Object System.Drawing.Font("Arial", 30)
  46.   }
  47. $textDisplay.Text = ""
  48.   $textDisplay.Text = $button1.Text + " One"
  49.   write-host $(Get-Date -Format FileDateTime)';' $textDisplay.Text
  50. })
  51. # button 2
  52. $button2 = New-Object System.Windows.Forms.Button
  53. $button2.Location = New-Object System.Drawing.Point(130, 520)
  54. $button2.Size = New-Object System.Drawing.Size(100, 50)
  55. $button2.Text = "2"
  56. $button2.Font = New-Object System.Drawing.Font("Arial", 15)
  57. $button2.BackColor = "Blue"
  58. $button2.ForeColor = "White"
  59. $button2.Add_Click({
  60.   if ($button2.BackColor-ne "Blue") {
  61.     $button2.BackColor = "Blue"
  62.     $button2.Font = New-Object System.Drawing.Font("Arial", 15)
  63.   } else {
  64.     $button2.BackColor = "Red"
  65.     $button2.Font = New-Object System.Drawing.Font("Arial", 30)
  66.   }
  67. $textDisplay.Text = ""
  68.   $textDisplay.Text = $button2.Text + " Two"
  69.   write-host $(Get-Date -Format FileDateTime)';' $textDisplay.Text
  70. })
  71. # button 3
  72. $button3 = New-Object System.Windows.Forms.Button
  73. $button3.Location = New-Object System.Drawing.Point(250, 520)
  74. $button3.Size = New-Object System.Drawing.Size(100, 50)
  75. $button3.Text = "3"
  76. $button3.Font = New-Object System.Drawing.Font("Arial", 15)
  77. $button3.BackColor = "Blue"
  78. $button3.ForeColor = "White"
  79. $button3.Add_Click({
  80.   if ($button3.BackColor-ne "Blue") {
  81.     $button3.BackColor = "Blue"
  82.     $button3.Font = New-Object System.Drawing.Font("Arial", 15)
  83.   } else {
  84.     $button3.BackColor = "Red"
  85.     $button3.Font = New-Object System.Drawing.Font("Arial", 30)
  86.   }
  87. $textDisplay.Text = ""
  88.   $textDisplay.Text = $button3.Text + " Three"
  89.   write-host $(Get-Date -Format FileDateTime)';' $textDisplay.Text
  90. })
  91. # button 4
  92. $button4 = New-Object System.Windows.Forms.Button
  93. $button4.Location = New-Object System.Drawing.Point(10, 580)
  94. $button4.Size = New-Object System.Drawing.Size(100, 50)
  95. $button4.Text = "4"
  96. $button4.Font = New-Object System.Drawing.Font("Arial", 15)
  97. $button4.BackColor = "Blue"
  98. $button4.ForeColor = "White"
  99. $button4.Add_Click({
  100.   if ($button4.BackColor-ne "Blue") {
  101.     $button4.BackColor = "Blue"
  102.     $button4.Font = New-Object System.Drawing.Font("Arial", 15)
  103.   } else {
  104.     $button4.BackColor = "Red"
  105.     $button4.Font = New-Object System.Drawing.Font("Arial", 30)
  106.   }
  107. $textDisplay.Text = ""
  108.   $textDisplay.Text = $button4.Text + " Four"
  109.   write-host $(Get-Date -Format FileDateTime)';' $textDisplay.Text
  110. })
  111. # button 5
  112. $button5 = New-Object System.Windows.Forms.Button
  113. $button5.Location = New-Object System.Drawing.Point(130, 580)
  114. $button5.Size = New-Object System.Drawing.Size(100, 50)
  115. $button5.Text = "5"
  116. $button5.Font = New-Object System.Drawing.Font("Arial", 15)
  117. $button5.BackColor = "Blue"
  118. $button5.ForeColor = "White"
  119. $button5.Add_Click({
  120.   if ($button5.BackColor-ne "Blue") {
  121.     $button5.BackColor = "Blue"
  122.     $button5.Font = New-Object System.Drawing.Font("Arial", 15)
  123.   } else {
  124.     $button5.BackColor = "Red"
  125.     $button5.Font = New-Object System.Drawing.Font("Arial", 30)
  126.   }
  127.   $textDisplay.Text = ""
  128.   $textDisplay.Text = $button5.Text + " Five"
  129.   write-host $(Get-Date -Format FileDateTime)';' $textDisplay.Text
  130. })
  131. # button 6
  132. $button6 = New-Object System.Windows.Forms.Button
  133. $button6.Location = New-Object System.Drawing.Point(250, 580)
  134. $button6.Size = New-Object System.Drawing.Size(100, 50)
  135. $button6.Text = "6"
  136. $button6.Font = New-Object System.Drawing.Font("Arial", 15)
  137. $button6.BackColor = "Blue"
  138. $button6.ForeColor = "White"
  139. $button6.Add_Click({
  140.   if ($button6.BackColor-ne "Blue") {
  141.     $button6.BackColor = "Blue"
  142.     $button6.Font = New-Object System.Drawing.Font("Arial", 15)
  143.   } else {
  144.     $button6.BackColor = "Red"
  145.     $button6.Font = New-Object System.Drawing.Font("Arial", 30)
  146.   }
  147. $textDisplay.Text = ""
  148.   $textDisplay.Text = $button6.Text + " Six"
  149.   write-host $(Get-Date -Format FileDateTime)';' $textDisplay.Text
  150. })
  151. # button 7
  152. $button7 = New-Object System.Windows.Forms.Button
  153. $button7.Location = New-Object System.Drawing.Point(10, 640)
  154. $button7.Size = New-Object System.Drawing.Size(100, 50)
  155. $button7.Text = "7"
  156. $button7.Font = New-Object System.Drawing.Font("Arial", 15)
  157. $button7.BackColor = "Blue"
  158. $button7.ForeColor = "White"
  159. $button7.Add_Click({
  160.   if ($button7.BackColor-ne "Blue") {
  161.     $button7.BackColor = "Blue"
  162.     $button7.Font = New-Object System.Drawing.Font("Arial", 15)
  163.   } else {
  164.     $button7.BackColor = "Red"
  165.     $button7.Font = New-Object System.Drawing.Font("Arial", 30)
  166.   }
  167. $textDisplay.Text = ""
  168.   $textDisplay.Text = $button7.Text + " Seven"
  169.   write-host $(Get-Date -Format FileDateTime)';' $textDisplay.Text
  170. })
  171. # button 8
  172. $button8 = New-Object System.Windows.Forms.Button
  173. $button8.Location = New-Object System.Drawing.Point(130, 640)
  174. $button8.Size = New-Object System.Drawing.Size(100, 50)
  175. $button8.Text = "8"
  176. $button8.Font = New-Object System.Drawing.Font("Arial", 15)
  177. $button8.BackColor = "Blue"
  178. $button8.ForeColor = "White"
  179. $button8.Add_Click({
  180.   if ($button8.BackColor-ne "Blue") {
  181.     $button8.BackColor = "Blue"
  182.     $button8.Font = New-Object System.Drawing.Font("Arial", 15)
  183.   } else {
  184.     $button8.BackColor = "Red"
  185.     $button8.Font = New-Object System.Drawing.Font("Arial", 30)
  186.   }
  187.   $textDisplay.Text = ""
  188.   $textDisplay.Text = $button8.Text + " Eight"
  189.   write-host $(Get-Date -Format FileDateTime)';' $textDisplay.Text
  190. })
  191. # button 9
  192. $button9 = New-Object System.Windows.Forms.Button
  193. $button9.Location = New-Object System.Drawing.Point(250, 640)
  194. $button9.Size = New-Object System.Drawing.Size(100, 50)
  195. $button9.Text = "9"
  196. $button9.Font = New-Object System.Drawing.Font("Arial", 15)
  197. $button9.BackColor = "Blue"
  198. $button9.ForeColor = "White"
  199. $button9.Add_Click({
  200.   if ($button9.BackColor-ne "Blue") {
  201.     $button9.BackColor = "Blue"
  202.     $button9.Font = New-Object System.Drawing.Font("Arial", 15)
  203.   } else {
  204.     $button9.BackColor = "Red"
  205.     $button9.Font = New-Object System.Drawing.Font("Arial", 30)
  206.   }
  207.   $textDisplay.Text = ""
  208.   $textDisplay.Text = $button9.Text + " Nine"
  209.   write-host $(Get-Date -Format FileDateTime)';' $textDisplay.Text
  210. })
  211. # button 0
  212. $button0 = New-Object System.Windows.Forms.Button
  213. $button0.Location = New-Object System.Drawing.Point(130, 700)
  214. $button0.Size = New-Object System.Drawing.Size(100, 50)
  215. $button0.Text = "0"
  216. $button0.Font = New-Object System.Drawing.Font("Arial", 15)
  217. $button0.BackColor = "Blue"
  218. $button0.ForeColor = "White"
  219. $button0.Add_Click({
  220.   if ($button0.BackColor-ne "Blue") {
  221.     $button0.BackColor = "Blue"
  222.     $button0.Font = New-Object System.Drawing.Font("Arial", 15)
  223.   } else {
  224.     $button0.BackColor = "Red"
  225.     $button0.Font = New-Object System.Drawing.Font("Arial", 30)
  226.   }
  227.   $textDisplay.Text = ""
  228.   $textDisplay.Text = $button0.Text + " Zero"
  229.   write-host $(Get-Date -Format FileDateTime)';' $textDisplay.Text
  230. })
  231.  
  232. # a-z key
  233. # Create the buttons for each letter
  234. $letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  235. $buttonX = 359
  236. $buttonY = 520
  237. $buttonWidth = 70
  238. $buttonHeight = 70
  239. $i = 0
  240. foreach ($letter in $letters.ToCharArray()) {
  241.     $i += 1
  242.     $button = New-Object System.Windows.Forms.Button
  243.     $button.Location = New-Object System.Drawing.Point($buttonX, $buttonY)
  244.     $button.Size = New-Object System.Drawing.Size($buttonWidth, $buttonHeight)
  245.     $button.Text = $letter
  246.     $button.BackColor = "Blue"
  247.     $button.ForeColor = "white"
  248.     $button.Add_Click({
  249.        
  250.         if ($form.activeControl.BackColor -ne "Blue") {
  251.            
  252.             $form.activeControl.Font = New-Object System.Drawing.Font("Arial", 15)
  253.         } else {
  254.            
  255.             $form.activeControl.Font = New-Object System.Drawing.Font("Arial", 30)
  256.         }
  257.  
  258.         $textDisplay.Text += $form.ActiveControl.Text
  259.                 write-host $(Get-Date -Format FileDateTime)';' $textDisplay.Text
  260.     })
  261.     $form.Controls.Add($button)
  262.     $buttonX += $buttonWidth + 10
  263.     if(($i % 10) -eq 0){
  264.         $buttonX = 359
  265.         $buttonY += $buttonHeight + 10
  266.     }
  267.    
  268. }
  269.  
  270.  
  271.             # Create the Sound button
  272.             # button Sound
  273.             $button2Sound = New-Object System.Windows.Forms.Button
  274.             $button2Sound.Location = New-Object System.Drawing.Point(10, 700)
  275.             $button2Sound.Size = New-Object System.Drawing.Size(100, 50)
  276.             $button2Sound.Text = "Play Sound"
  277.             $button2Sound.BackColor = "Blue"
  278.             $button2Sound.ForeColor = "White"
  279.             $button2Sound.Add_Click({
  280.                            
  281.                 if ($button2Sound.BackColor -ne "Blue") {
  282.                     $button2Sound.BackColor = "Blue"
  283.                     $button2Sound.Font = New-Object System.Drawing.Font("Arial", 15)
  284.                     $sound = New-Object System.Media.SoundPlayer ".\chimes.wav"
  285.                     $sound.Play()
  286.                     write-host $(Get-Date -Format FileDateTime)';' "Play .\chimes.wav"
  287.                   } else {
  288.                     $button2Sound.BackColor = "Green"
  289.                     $button2Sound.Font = New-Object System.Drawing.Font("Arial", 15)
  290.                     $sound = New-Object System.Media.SoundPlayer ".\s.wav"
  291.                     $sound.Play()
  292.                     write-host $(Get-Date -Format FileDateTime)';' "Play .\s.wav"
  293.                   }
  294.                 $textDisplay.Text = $button2Sound.Text
  295.  
  296.             })
  297.            
  298.             # Create a Image button
  299.             # button Image
  300.             $buttonClear = New-Object System.Windows.Forms.Button
  301.             # $buttonClear.hide()
  302.             $buttonClear.Text = "Clear"
  303.             $buttonClear.BackColor = "Blue"
  304.             $buttonClear.ForeColor = "White"
  305.             $buttonClear.Size = New-Object System.Drawing.Size(100, 50)
  306.             $buttonClear.Location = New-Object System.Drawing.Point(250, 700)
  307.  
  308.  
  309.             # Add a click event to the button
  310.             $buttonClear.Add_Click({
  311.                
  312.                 if ($buttonClear.BackColor -ne "Blue") {
  313.                     $buttonClear.BackColor = "Blue"
  314.                     $buttonClear.Font = New-Object System.Drawing.Font("Arial", 15)
  315.                   } else {
  316.                     $buttonClear.BackColor = "Green"
  317.                     $buttonClear.Font = New-Object System.Drawing.Font("Arial", 15)
  318.                   }
  319.  
  320.                 $textDisplay.Text = ""
  321.                 # Show the image
  322.                 # $image = [System.Drawing.Image]::FromFile(".\keyboard.png")
  323.                 # $pictureBox.Image = $image
  324.                 write-host $(Get-Date -Format FileDateTime)';' "clear"
  325.             })
  326.  
  327.             # Create a picture box
  328.             $pictureBox = New-Object System.Windows.Forms.PictureBox
  329.             $pictureBox.Width = 994
  330.             $pictureBox.Height = 321
  331.             $pictureBox.Location = New-Object System.Drawing.Point(420, 520)
  332.  
  333.             # Add the button to the form
  334.             $form.Controls.Add($button2Sound)
  335.  
  336.             # Add the button and picture box to the form
  337.             $form.Controls.Add($buttonClear)
  338.             $form.Controls.Add($pictureBox)
  339.  
  340.  
  341. # Add buttons to the form
  342. $form.Controls.Add($button1)
  343. $form.Controls.Add($button2)
  344. $form.Controls.Add($button3)
  345. $form.Controls.Add($button4)
  346. $form.Controls.Add($button5)
  347. $form.Controls.Add($button6)
  348. $form.Controls.Add($button7)
  349. $form.Controls.Add($button8)
  350. $form.Controls.Add($button9)
  351. $form.Controls.Add($button0)
  352. $form.Controls.Add($textDisplay)
  353.  
  354. # Show the form
  355. $form.ShowDialog() | Out-Null
  356. stop-transcript
Add Comment
Please, Sign In to add comment