我試圖讓(我第一次)C#程序:不能使用System.Windows.Forms的
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("hello");
Console.ReadLine();
}
}
}
這遠遠,但使用System.Windows.Forms的,如果我嘗試:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("hello");
System.MessageBox("hello");
Console.ReadLine();
}
}
}
這是錯誤我得到:
Error 1 The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?) C:\Users\Ramy\Documents\Visual Studio 2010\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs 5 14 ConsoleApplication1
一些細節: - 我使用Visual Studio 2012; - 我已經安裝了.NET Development Kit; - 它是一個控制檯應用程序。
也許是因爲在控制檯上應用程序不能使用System.Windows.Forms? 如果是這樣,程序應該是什麼?我也嘗試過一種形式,但我只是顯示一個窗口而沒有代碼。
有時候錯誤信息會告訴你什麼是錯的:你缺少一個程序集引用。 [如何在Visual Studio中添加或刪除引用](http://msdn.microsoft.com/zh-cn/library/wkze6zky。aspx) – dtb 2012-03-10 13:11:56
因爲這只是您的第一個程序,所以最好重新開始並創建Windows窗體應用程序。 VS2010項目嚮導將關注許多關於使用Windows窗體的數據集。 – Steve 2012-03-10 13:18:30
dtb的評論的第一部分有點不爲人知。很明顯,提問者缺少一個程序集引用。問題是如何解決這個問題,因爲錯誤信息沒有澄清。 – jmort253 2013-02-28 23:46:01