wetyukmnbxc

Untitled

Mar 6th, 2023 (edited)
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # This script creates a form with a button labeled "Play Sound". When the button is clicked, it creates a `System.Media.SoundPlayer` object and plays the sound file located at "C:\Windows\Media\chimes.wav". You can replace this file path with the path to your own sound file.
  2.  
  3.  
  4. # Write a powershell script , also add a new button. When the button is clicked , a picture is shown in the GUI.
  5.  
  6. # Here's a PowerShell script that creates a GUI with a button that displays an image when clicked:
  7.  
  8. Add-Type -AssemblyName System.Windows.Forms
  9.  
  10. # Create a form
  11. $form = New-Object System.Windows.Forms.Form
  12. $form.Text = "Image Viewer"
  13. $form.Width = 400
  14. $form.Height = 400
  15.  
  16. # Create a button
  17. $button = New-Object System.Windows.Forms.Button
  18. $button.Text = "Show Image"
  19. $button.Width = 100
  20. $button.Height = 30
  21. $button.Location = New-Object System.Drawing.Point(170, 25)
  22.  
  23.  
  24. # Create the button
  25. $button2 = New-Object System.Windows.Forms.Button
  26. $button2.Location = New-Object System.Drawing.Point(50, 25)
  27. $button2.Size = New-Object System.Drawing.Size(100, 50)
  28. $button2.Text = "Play Sound"
  29. $button2.Add_Click({
  30.     $sound = New-Object System.Media.SoundPlayer ".\chimes.wav"
  31.     $sound.Play()
  32. })
  33.  
  34.  
  35. # Add a click event to the button
  36. $button.Add_Click({
  37.     # Show the image
  38.     $image = [System.Drawing.Image]::FromFile(".\1.jpg")
  39.     $pictureBox.Image = $image
  40. })
  41.  
  42. # Create a picture box
  43. $pictureBox = New-Object System.Windows.Forms.PictureBox
  44. $pictureBox.Width = 300
  45. $pictureBox.Height = 300
  46. $pictureBox.Location = New-Object System.Drawing.Point(170, 100)
  47.  
  48. # Add the button to the form
  49. $form.Controls.Add($button2)
  50.  
  51. # Add the button and picture box to the form
  52. $form.Controls.Add($button)
  53. $form.Controls.Add($pictureBox)
  54.  
  55. # Show the form
  56. $form.ShowDialog() | Out-Null
  57.  
  58. # Make sure to replace "C:\path\to\image.jpg" with the actual path to your image file.
Add Comment
Please, Sign In to add comment