无法使用System.Windows.Forms [英] Can't use System.Windows.Forms

查看:549
本文介绍了无法使用System.Windows.Forms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经尝试制作C#程序:

I have tried making (my first) a C# program:

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:

This goes well, but if I try using 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开发套件; -这是一个控制台应用程序.

Some details: - I am using Visual Studio 2012; - I have installed the .NET Development Kit; - It is a Console Application.

也许是因为在控制台应用程序上无法使用System.Windows.Forms? 如果是这样,应该使用什么程序?我也尝试过使用表单,但是我只显示一个窗口,没有任何代码.

Maybe it's because on a Console Application can't use System.Windows.Forms? If so, what program should be? I also have tried with a form, but I was only displaying a window and no code.

推荐答案

控制台应用程序不会自动添加对System.Windows.Forms.dll的引用.

A console application does not automatically add a reference to System.Windows.Forms.dll.

在解决方案资源管理器中右键单击您的项目,然后选择添加引用...",然后找到System.Windows.Forms并将其添加.

Right-click your project in Solution Explorer and select Add reference... and then find System.Windows.Forms and add it.

这篇关于无法使用System.Windows.Forms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆