I write the piano. When you press a key, a Click event occurs, a sound is played.
private void Form1_KeyDown(Object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.D1: if (!isPressed) { isPressed = true; button1.PerformClick(); } label5.Text = "1"; break; } private void Form1_KeyUp(Object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.D1: isPressed = false; break; } } public void sound(string path) { var p1 = new MediaPlayer(); p1.Open(new Uri(path, UriKind.Relative)); p1.Play(); } private void button1_Click(Object sender, EventArgs e) { s.sound(@"s//_1.wav"); label3.Text = "До / 1"; } Question: how to interrupt the playback of the sound of a note depending on the release of a key? Suppose we press and hold the key, the sound is played completely, when released, the sound stops, while simultaneously pressing the other keys, the sound on all the buttons will be played.