我正在尝试改进Microsoft指导的练习创建数学测验,并且我想在NumericUpDown中输入的值正确时播放声音。
private void Answer_Enter(object sender, EventArgs e)
{
NumericUpDown answerBox = sender as NumericUpDown;
if (answerBox != null)
{
int LengthofAnswer = somma.Value.ToString().Length;
answerBox.Select(0, LengthofAnswer);
}
if (answerBox.Value == (add1 + add2) || answerBox.Value == (sott1 - sott2) || answerBox.Value == (molt1 * molt2) || answerBox.Value == (div1 / div2))
{
Correct();
}
}
这是方法 Correct():
private void Correct()
{
SoundPlayer correct = new SoundPlayer(@"C:\Sounds\Right.wav");
correct.Play();
}
这样,声音会播放,但会连续播放。
播放完一次声音后如何停止播放声音?