1. ホーム
  2. c#

[解決済み] System.Windows.Formsは使用できません。

2022-02-28 20:01:36

質問

C#のプログラムを作ってみた(初めて)。

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.Forms.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が使用できないからでしょうか? もしそうなら、どんなプログラムにすればいいのでしょうか?フォームで試したこともあるのですが、ウィンドウが表示されるだけでコードが表示されないのです。

どうすればいいですか?

コンソールアプリケーションで System.Windows.Forms.dll への参照が自動的に追加されない。

Solution Explorer でプロジェクトを右クリックし、Add reference... を選択して System.Windows.Forms を探し、追加します。