Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Can you write a powershell script to make a GUI. Add one button. When this button is clicked, it triggers an event that a sound file is played.
- Sure, here's a PowerShell script that creates a GUI with a button that plays a sound file when clicked:
- Add-Type -AssemblyName System.Windows.Forms
- Add-Type -AssemblyName System.Drawing
- # Create the form
- $form = New-Object System.Windows.Forms.Form
- $form.Text = "Play Sound"
- $form.Size = New-Object System.Drawing.Size(200, 100)
- $form.StartPosition = "CenterScreen"
- # Create the button
- $button = New-Object System.Windows.Forms.Button
- $button.Location = New-Object System.Drawing.Point(50, 25)
- $button.Size = New-Object System.Drawing.Size(100, 50)
- $button.Text = "Play Sound"
- $button.Add_Click({
- $sound = New-Object System.Media.SoundPlayer "C:\Windows\Media\chimes.wav"
- $sound.Play()
- })
- # Add the button to the form
- $form.Controls.Add($button)
- # Show the form
- $form.ShowDialog() | Out-Null
- 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.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement