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

时间:2012-08-05 09:20:03

标签: c# xna xna-4.0 messagebox dialogresult

我将以下代码作为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 ...”但似乎“系统”中没有“窗口”...

我该如何解决这个问题?

3 个答案:

答案 0 :(得分:4)

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

对于游戏内GUI,存在this one等各种解决方案; thisthisthis SO question中包含更多链接,而this MSDN forum posting包含另一个链接列表。

答案 1 :(得分:0)

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

答案 2 :(得分:0)

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