Question

I'm having the following code as part of my XNA game:

    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();
        }
    }       

For some reason,I received the following errors:

"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"  

I'm tring to add "System.Windows..." but it seems like that "System" does not have "windows" in it...

How can I solve this?

Was it helpful?

Solution

It seems that you are trying to use WinForms classes in XNA. However, according to the docs, WinForms is not included in XNA: As can be seen in the MessageBox docs, none of the MessageBox methods has the XNA logo in the first column, which means that none of them is supported in XNA. (See, for contrast, the docs on System.Linq.Enumerable, where all methods have the X-shaped XNA logo next to them).

For in-game GUIs, various solutions such as this one exist; more links are included in this, this and this SO question and this MSDN forum posting contains another list of links.

OTHER TIPS

OK, I found the solution...
Very simple :/
Adding the "System.Windows" to the "References" section in the project :)

Also, if you try to bring in System.Windows.Forms, and you are using XNA's keys, like Keys.Up, there will be a name conflict with System.Windows.Forms Keys.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top