XNA上的MessageBox和对话框(C#)

我将以下代码作为我的XNA游戏的一部分:

private void gameOver() { if (!m_IsGameOver) { string message = String.Format("GAME OVER!!!{0}Your score is: {1}", Environment.NewLine, GameScore); if (MessageBox.Show(message, "GameOver", MessageBoxButtons.OK) == DialogResult.OK) { this.Exit(); } m_IsGameOver = true; } } private void gameWon() { string message = String.Format("You Won!!!{0}Your score is: {1}", Environment.NewLine, GameScore); if (MessageBox.Show(message, "You Won!", MessageBoxButtons.OK) == DialogResult.OK) { this.Exit(); } } 

出于某种原因,我收到以下错误:

 "The name 'MessageBox' does not exist in the current context" "The name 'MessageBoxButtons' does not exist in the current context" "The name 'DialogResult' does not exist in the current context" 

我想添加“System.Windows …”,但似乎“系统”中没有“窗口”……

我怎么解决这个问题?

您似乎正在尝试在XNA中使用WinForms类。 但是,根据文档,WinForms不包含在XNA中:从MessageBox文档中可以看出,没有任何MessageBox方法在第一列中具有XNA徽标,这意味着XNA中不支持它们。 (相比之下,请参阅System.Linq.Enumerable上的文档 ,其中所有方法旁边都有X形XNA徽标)。

对于游戏内GUI,存在诸如此类的各种解决方案; 更多链接包含在此 , 此和此SO问题和此MSDN论坛发布包含另一个链接列表。

好的,我找到了解决方案……
非常简单 :/
将“System.Windows”添加到项目中的“References”部分:)

此外,如果您尝试引入System.Windows.Forms,并且您正在使用XNA的密钥,例如Keys.Up,则会出现与System.Windows.Forms密钥的名称冲突。