目前,当用户通过媒体播放器播放音乐时,我的XNA游戏启动时会弹出一个消息框。它有两个按钮,是和否。我需要做的是确定用户按下了哪个按钮,这样我就可以根据结果使用IF语句来执行相关操作。目前我的代码是:
Public Sub playmusic()
FrameworkDispatcher.Update()
If MediaPlayer.GameHasControl = False Then
'Add everything below when you want to show the message box
Dim MBOPTIONS As New List(Of String)()
MBOPTIONS.Add("Yes")
MBOPTIONS.Add("No")
Dim result As IAsyncResult = Guide.BeginShowMessageBox("Music request", "Do you want to stop your music and play the in-game music?", MBOPTIONS, 0, MessageBoxIcon.Alert, Nothing, Nothing)
result.AsyncWaitHandle.WaitOne()
Dim choice As System.Nullable(Of Integer) = Guide.EndShowMessageBox(result)
If choice.HasValue Then
If choice.Value = 0 Then
MediaPlayer.Stop()
sounds = True
Else
sounds = False
End If
End If
End If
End Sub
任何人都可以根据我需要读取结果的代码来帮助我吗?