Advertisement
wetyukmnbxc

Untitled

Mar 5th, 2023
97
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 4 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 4 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.  
  8. # Create a new form
  9. $form = New-Object System.Windows.Forms.Form
  10. $form.Text = "Button Demo"
  11. $form.Size = New-Object System.Drawing.Size(300, 300)
  12. $form.StartPosition = "CenterScreen"
  13.  
  14. # Create 4 buttons
  15. $button1 = New-Object System.Windows.Forms.Button
  16. $button1.Location = New-Object System.Drawing.Point(20, 20)
  17. $button1.Size = New-Object System.Drawing.Size(100, 50)
  18. $button1.Text = "Button 1"
  19. $button1.BackColor = "Blue"
  20. $button1.Add_Click({
  21. if($button1.BackColor -ne "Blue")
  22. {
  23. $button1.BackColor = "Blue"
  24. }
  25. else
  26. {
  27. $button1.BackColor = "Red"
  28. }
  29. })
  30.  
  31. $button2 = New-Object System.Windows.Forms.Button
  32. $button2.Location = New-Object System.Drawing.Point(140, 20)
  33. $button2.Size = New-Object System.Drawing.Size(100, 50)
  34. $button2.Text = "Button 2"
  35. $button2.BackColor = "Blue"
  36. $button2.Add_Click({
  37. if($button2.BackColor -ne "Blue")
  38. {
  39. $button2.BackColor = "Blue"
  40. }
  41. else
  42. {
  43. $button2.BackColor = "Red"
  44. }
  45. })
  46.  
  47. $button3 = New-Object System.Windows.Forms.Button
  48. $button3.Location = New-Object System.Drawing.Point(20, 80)
  49. $button3.Size = New-Object System.Drawing.Size(100, 50)
  50. $button3.Text = "Button 3"
  51. $button3.BackColor = "Blue"
  52. $button3.Add_Click({
  53.   if($button3.BackColor -ne "Blue")
  54. {
  55. $button3.BackColor = "Blue"
  56. }
  57. else
  58. {
  59. $button3.BackColor = "Red"
  60. }
  61. })
  62.  
  63. $button4 = New-Object System.Windows.Forms.Button
  64. $button4.Location = New-Object System.Drawing.Point(140, 80)
  65. $button4.Size = New-Object System.Drawing.Size(100, 50)
  66. $button4.Text = "Button 4"
  67. $button4.BackColor = "Blue"
  68. $button4.Add_Click({
  69. if($button4.BackColor -ne "Blue")
  70. {
  71. $button4.BackColor = "Blue"
  72. }
  73. else
  74. {
  75. $button4.BackColor = "Red"
  76. }
  77.  
  78. })
  79.  
  80. # Add buttons to the form
  81. $form.Controls.Add($button1)
  82. $form.Controls.Add($button2)
  83. $form.Controls.Add($button3)
  84. $form.Controls.Add($button4)
  85.  
  86. # Show the form
  87. $form.ShowDialog() | Out-Null
  88.  
  89.  
  90. # This script uses the `System.Windows.Forms` assembly to create a new form and 4 buttons. Each button is given a blue background color and an event handler that changes the background color to red when the button is clicked. Finally, the buttons are added to the form and the form is displayed using the `ShowDialog()` method.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement