Advertisement
wetyukmnbxc

Untitled

Mar 9th, 2023
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Write a powershell script , also add 26 new buttons. Each of the 26 buttons represent alphabets a to z. When 1 of the 26 buttons is clicked , the corresponding alphabet is shown in the GUI.
  2.  
  3. # Here's a PowerShell script that creates a GUI with 26 buttons representing the letters A to Z. When a button is clicked, the corresponding letter is displayed in a label:
  4.  
  5.  
  6. Add-Type -AssemblyName System.Windows.Forms
  7.  
  8. # Create the form
  9. $form = New-Object System.Windows.Forms.Form
  10. $form.Text = "Alphabet Buttons"
  11. $form.Size = New-Object System.Drawing.Size(300, 200)
  12. $form.StartPosition = "CenterScreen"
  13.  
  14. # Create the label to display the selected letter
  15. $label = New-Object System.Windows.Forms.Label
  16. $label.Location = New-Object System.Drawing.Point(100, 50)
  17. $label.Size = New-Object System.Drawing.Size(100, 50)
  18. $form.Controls.Add($label)
  19.  
  20. # Create the buttons for each letter
  21. $letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  22. $buttonX = 20
  23. $buttonY = 100
  24. $buttonWidth = 20
  25. $buttonHeight = 20
  26. foreach ($letter in $letters.ToCharArray()) {
  27.     $button = New-Object System.Windows.Forms.Button
  28.     $button.Location = New-Object System.Drawing.Point($buttonX, $buttonY)
  29.     $button.Size = New-Object System.Drawing.Size($buttonWidth, $buttonHeight)
  30.     $button.Text = $letter
  31.     $button.Add_Click({
  32.         $label.Text = $button.Text
  33.     })
  34.     $form.Controls.Add($button)
  35.     $buttonX += $buttonWidth + 5
  36. }
  37.  
  38. # Show the form
  39. $form.ShowDialog() | Out-Null
  40.  
  41.  
  42. This script creates a form with a label and 26 buttons, one for each letter of the alphabet. When a button is clicked, the corresponding letter is displayed in the label. You can customize the size and position of the form, label, and buttons by modifying the values in the script.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement