Andrew Henz Andrew Henz - 3 months ago 10
Vb.net Question

Play sound on Click Event

Can I make a program that plays a sound every time I click on it somewhere? I really need this. Like, in some operating systems, it plays a sound everytime you click on a window.

Answer

The examples are shown using the Button_Click Event.

Playing System Sounds

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click            
        My.Computer.Audio.PlaySystemSound( _
        System.Media.SystemSounds.Exclamation)
    End Sub

Playing Specified Sounds

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        My.Computer.Audio.Play("C:\Mysound.wav", _
        AudioPlayMode.BackgroundLoop)
    End Sub
Comments