如何在XNA 之中加入開檔 openFileDialog 。
以下方法也適用於其他Visual Studio 2010 平台的其他語言以及環境。
XNA一開始是不存在Windows.Form元件的,
所以要使用的時候會發生錯誤如下圖。
ThreadStateException was unhandled 的錯誤。
所以該如何解決呢!?
首先我們必須在標頭檔先加入。
using System.Windows.Forms;
並且在參考加入引用元件也加入如以上之Form元件。
接下來就是在主程式進入點(Program.cs)加入以下程式碼 請注意加入的地方。
using System;
using System.Windows.Forms;
namespace MainMenu
{
#if WINDOWS || XBOX
static class Program
{
////////////////在此處加入 /////////////////////////////
[STAThread]
static void Main(string[] args)
{
using (Game1 game = new Game1())
{
game.Run();
}
}
}
#endif
}
原因為什麼請參考如這篇 以及微軟MSDN說明
沒有留言:
張貼留言