Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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.
- # Write a powershell script , also add a new button. When the button is clicked , a picture is shown in the GUI.
- # Here's a PowerShell script that creates a GUI with a button that displays an image when clicked:
- Add-Type -AssemblyName System.Windows.Forms
- # Create a form
- $form = New-Object System.Windows.Forms.Form
- $form.Text = "Image Viewer"
- $form.Width = 400
- $form.Height = 400
- # Create a button
- $button = New-Object System.Windows.Forms.Button
- $button.Text = "Show Image"
- $button.Width = 100
- $button.Height = 30
- $button.Location = New-Object System.Drawing.Point(170, 25)
- # Create the button
- $button2 = New-Object System.Windows.Forms.Button
- $button2.Location = New-Object System.Drawing.Point(50, 25)
- $button2.Size = New-Object System.Drawing.Size(100, 50)
- $button2.Text = "Play Sound"
- $button2.Add_Click({
- $sound = New-Object System.Media.SoundPlayer ".\chimes.wav"
- $sound.Play()
- })
- # Add a click event to the button
- $button.Add_Click({
- # Show the image
- $image = [System.Drawing.Image]::FromFile(".\1.jpg")
- $pictureBox.Image = $image
- })
- # Create a picture box
- $pictureBox = New-Object System.Windows.Forms.PictureBox
- $pictureBox.Width = 300
- $pictureBox.Height = 300
- $pictureBox.Location = New-Object System.Drawing.Point(170, 100)
- # Add the button to the form
- $form.Controls.Add($button2)
- # Add the button and picture box to the form
- $form.Controls.Add($button)
- $form.Controls.Add($pictureBox)
- # Show the form
- $form.ShowDialog() | Out-Null
- # 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