0

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?

Bridge
  • 29,818
  • 9
  • 60
  • 82
Inbali
  • 107
  • 1
  • 7

3 Answers3

4

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.

Community
  • 1
  • 1
O. R. Mapper
  • 20,083
  • 9
  • 69
  • 114
0

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

Inbali
  • 107
  • 1
  • 7
  • As far as I can tell from statements on e.g. [this site](http://create.msdn.com/en-US/education/catalog/sample/winforms_series_1) and [this site](http://forums.create.msdn.com/forums/t/30455.aspx), non-PC XNA environments such as Xbox don't support WinForms. That means, your game will not run there if you reference WinForms. Also note that `System.Windows.Forms.MessageBox` (which you're attempting to use in your question) is in `System.Windows.Forms.dll`. – O. R. Mapper Aug 05 '12 at 09:54
  • It can work though, but only if you've no plans to port it to other non-PC platforms. – Steven May 02 '17 at 15:13
0

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.

Isaac Dee
  • 38
  • 1
  • 2
  • 10