0

I made a console application with the VS Code C# extension. I need a couple of classes from System.Windows.Forms, like Screen and Cursor. While I can access System.Windows.Forms itself, the classes in question aren't there. Are there some other references I need to add?

This is what my csproj file looks like:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net5.0-windows</TargetFramework>
        <UseWindowsForms>true</UseWindowsForms>
    </PropertyGroup>
</Project>
user1854611
  • 121
  • 8
  • Forms and console apps are separate things, you can't 'borrow' forms classes for a console app. What cursor are you trying to set in a console app? – Neil May 06 '21 at 18:48
  • I'm trying to get the current screen resolution and control the mouse cursor. – user1854611 May 06 '21 at 18:52
  • 1
    So, to get the screen width https://learn.microsoft.com/en-us/dotnet/api/system.windows.systemparameters.virtualscreenwidth?view=net-5.0#System_Windows_SystemParameters_VirtualScreenWidth and for moving the mouse, I think you will have to use PInvoke https://www.pinvoke.net/default.aspx/user32.setcursorpos – Neil May 06 '21 at 18:57
  • 1
    screen resolution: https://stackoverflow.com/questions/47930612/get-screen-resolution-in-console-app – Nikki9696 May 07 '21 at 15:18
  • 1
    and for cursor: https://learn.microsoft.com/en-us/dotnet/api/system.console.setcursorposition?view=net-5.0 – Nikki9696 May 07 '21 at 15:19

0 Answers0