I have a problem with Visual Studio 2017 when I try using the screen class:
Error CS0246 The type or namespace name 'Screen' could not be found (are you missing a using directive or an assembly reference?
Error CS0234 The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)
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;
}
}
}
The main problem here is you are in a console app, and calling a winforms library.
Gets an array of all displays on the system.
- Namespace : System.Windows.Forms
- Assembly : System.Windows.Forms (in System.Windows.Forms.dll)
The above is very important
When you have a problem like this, try and look on line for the documentation
What is says, is you need to add the assembly System.Windows.Forms
to your application.
How to: Add or Remove References By Using the Add Reference Dialog Box
To add a reference in Visual C#
In Solution Explorer, right-click the project node and click Add Reference.
In the Add Reference dialog box, select the tab indicating the type of component you want to reference.
Select the components you want to reference, and then click OK.
It seems you don't have a reference to the System.Windows.Forms
library.
Project
menu Add reference
Assemblies
(on the left) System.Windows.Forms
Of course this will only work with a .NET Framework project, so if yours isn't it won't work ( System.Windows.Forms
won't work).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.