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

编程入门 行业动态 更新时间:2024-10-27 23:21:59
XNA上的MessageBox和对话框(C#)(MessageBox & Dialogs on XNA (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 ...”,但似乎“系统”中没有“窗口”......

我怎么解决这个问题?

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?

最满意答案

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

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

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.

更多推荐

本文发布于:2023-07-30 13:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1337869.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对话框   XNA   MessageBox   Dialogs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!