I am looking for a way to turn an ordinary C# Winform button into a sort of push button to play a wav file when pressed and held in and pause it when you release the button.
Is there an easy way of doing this?
I am looking for a way to turn an ordinary C# Winform button into a sort of push button to play a wav file when pressed and held in and pause it when you release the button.
Is there an easy way of doing this?
Simply play the file when the mouse is down and stop the player when the mouse is up again:
SoundPlayer soundPlayer = new SoundPlayer(pathToWavFile);
private void yourButton_MouseDown(object sender, MouseEventArgs e) {
soundPlayer.Play();
}
private void yourButton_MouseUp(object sender, MouseEventArgs e) {
soundPlayer.Stop();
}