我尝试使用屏幕类时遇到Visual Studio 2017的问题:
错误CS0246找不到类型或命名空间名称“屏幕”(您是否缺少using指令或程序集引用?
错误CS0234名称空间'System.Windows'中不存在类型或命名空间名称'Forms'(您是否缺少程序集引用?)
https://msdn.microsoft.com/en-us/library/system.windows.forms.screen.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Screen[] screens = Screen.AllScreens;
}
}
}
2 回答
这里的主要问题是你在一个控制台应用程序,并调用winforms库 .
Screen.AllScreens Property
以上是非常重要的
当您遇到这样的问题时,请尝试在线查看文档
说的是,您需要将程序集
System.Windows.Forms
添加到您的应用程序中 .How to: Add or Remove References By Using the Add Reference Dialog Box
看来你没有对
System.Windows.Forms
库的引用 .转到
Project
菜单选择
Add reference
点击
Assemblies
(左侧)检查
System.Windows.Forms
单击“确定”
当然这只适用于.NET Framework项目,所以如果你的工作没有't it won'工作(
System.Windows.Forms
将不起作用) .