gpt4 book ai didi

c# - 无法使用 System.Windows.Forms

转载 作者:IT王子 更新时间:2023-10-29 03:42:19 26 4
gpt4 key购买 nike

我已经尝试制作(我的第一个)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:

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 开发工具包;- 这是一个控制台应用程序。

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

最佳答案

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

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

关于c# - 无法使用 System.Windows.Forms,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9646684/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com