Advertisement
wetyukmnbxc

Untitled

Mar 4th, 2023
119
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, 150)
  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.    $button1.BackColor = "Red"
  22. })
  23.  
  24. $button2 = New-Object System.Windows.Forms.Button
  25. $button2.Location = New-Object System.Drawing.Point(140, 20)
  26. $button2.Size = New-Object System.Drawing.Size(100, 50)
  27. $button2.Text = "Button 2"
  28. $button2.BackColor = "Blue"
  29. $button2.Add_Click({
  30.    $button2.BackColor = "Red"
  31. })
  32.  
  33. $button3 = New-Object System.Windows.Forms.Button
  34. $button3.Location = New-Object System.Drawing.Point(20, 80)
  35. $button3.Size = New-Object System.Drawing.Size(100, 50)
  36. $button3.Text = "Button 3"
  37. $button3.BackColor = "Blue"
  38. $button3.Add_Click({
  39.    $button3.BackColor = "Red"
  40. })
  41.  
  42. $button4 = New-Object System.Windows.Forms.Button
  43. $button4.Location = New-Object System.Drawing.Point(140, 80)
  44. $button4.Size = New-Object System.Drawing.Size(100, 50)
  45. $button4.Text = "Button 4"
  46. $button4.BackColor = "Blue"
  47. $button4.Add_Click({
  48.    $button4.BackColor = "Red"
  49. })
  50.  
  51. # Add buttons to the form
  52. $form.Controls.Add($button1)
  53. $form.Controls.Add($button2)
  54. $form.Controls.Add($button3)
  55. $form.Controls.Add($button4)
  56.  
  57. # Show the form
  58. $form.ShowDialog() | Out-Null
  59.  
  60.  
  61. 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