好的,所以我已经使用visual studio 2010完成了一个名为lucky 7的游戏。我想在赢得游戏时播放声音(在三个插槽之一中获得7)。下面是代码:在vb中播放声音
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
For i = 0 To 2
slots(i) = rand.Next(10)
Next
Label1.Text = (slots(0).ToString)
Label2.Text = (slots(1).ToString)
Label3.Text = (slots(2).ToString)
If slots(0) = 7 Or slots(1) = 7 Or slots(2) = 7 Then
score = score + 100 'REM 10 points for each win
Label4.Text = (score.ToString)
PictureBox1.Visible = True 'REM If you have a PictureBox
PlaySound "C:\WINDOWS\MEDIA\TADA.WAV",
Else
PictureBox1.Visible = False
End If
If score = 500 Then
MsgBox("You Scored 500 Points!", vbInformation)
End If
End Sub
事情是,我上“playsound”语句错误,我真的很想当玩家赢得游戏玩的声音!
我也尝试创建一个重置按钮,它将得分和所有三个插槽重新设置为0,但是当我点击它时,什么也没有发生。下面是重置按钮的代码:
你有没有通过代码走,以确保没有发生任何事情上的按钮单击事件使用My.Computer.Audio.Play
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
score = 0
PictureBox1.Visible = False
End Sub
当我使用“My.Computer.Audio.Play(tada.wav)”时仍然不起作用,我收到错误消息。 – user2262982
什么错误?您需要在引号中包含“tada.wav”,并且可能需要提供整个路径。另外,即使该声音是与OS一起发送的,您也无法确定它会在客户端计算机上。 或者,您可以使用 My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Exclamation) 声音不太一样。 – DBNickel
您还可以添加声音作为资源: http://stackoverflow.com/questions/7116669/how-to-play-wav-in-vb-net-from-resources – DBNickel