首页 文章

Visual Studio 2017无法识别Screen类

提问于
浏览
-1

我尝试使用屏幕类时遇到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 回答

  • 2

    这里的主要问题是你在一个控制台应用程序,并调用winforms库 .

    Screen.AllScreens Property

    获取系统上所有显示的数组 . 命名空间:System.Windows.Forms程序集:System.Windows.Forms(在System.Windows.Forms.dll中)

    以上是非常重要的

    当您遇到这样的问题时,请尝试在线查看文档

    说的是,您需要将程序集 System.Windows.Forms 添加到您的应用程序中 .

    How to: Add or Remove References By Using the Add Reference Dialog Box

    在Visual C#中添加引用在“解决方案资源管理器”中,右键单击项目节点,然后单击“添加引用” . 在“添加引用”对话框中,选择指示要引用的组件类型的选项卡 . 选择要引用的组件,然后单击“确定” .

  • 0

    看来你没有对 System.Windows.Forms 库的引用 .

    • 转到 Project 菜单

    • 选择 Add reference

    • 点击 Assemblies (左侧)

    • 检查 System.Windows.Forms

    • 单击“确定”

    当然这只适用于.NET Framework项目,所以如果你的工作没有't it won'工作( System.Windows.Forms 将不起作用) .

相关问题