Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用.NET Core 5确定屏幕大小?_C#_.net_.net Core_.net 5 - Fatal编程技术网

C# 使用.NET Core 5确定屏幕大小?

C# 使用.NET Core 5确定屏幕大小?,c#,.net,.net-core,.net-5,C#,.net,.net Core,.net 5,如何使用.NET Core确定屏幕大小?我想拍摄中所述的屏幕截图,但他们使用的是固定的1920*1080分辨率,这不符合我的目的 我是否必须引用System.Windows.Forms并因此被钉在Windows上 在切换到.NET Core之前,我们使用System.Windows.Forms,如下所示: new Size { Width = Screen.AllScreens.Sum(s => s.Bounds.Width), Height = Screen.AllScreens

如何使用.NET Core确定屏幕大小?我想拍摄中所述的屏幕截图,但他们使用的是固定的1920*1080分辨率,这不符合我的目的

我是否必须引用System.Windows.Forms并因此被钉在Windows上

在切换到.NET Core之前,我们使用System.Windows.Forms,如下所示:

new Size
{
  Width = Screen.AllScreens.Sum(s => s.Bounds.Width),
  Height = Screen.AllScreens.Max(s => s.Bounds.Height)
}

这是我们可以再次使用的东西,但我们当然会喜欢独立于平台的东西。

评论暗示它还不受支持

因此,我向您展示了我们如何使用Windows窗体实现它(我花了一些时间了解如何在.NET核心库项目中正确引用Windows窗体):

您可以像这样将Windows窗体依赖项添加到csproj文件:

<ItemGroup>
  <FrameworkReference Include="Microsoft.WindowsDesktop.App.WindowsForms" />
</ItemGroup>

重要提示:这只适用于Windows,但至少它与.NET Core兼容。

虽然System.Drawing可以跨平台使用,但如果CopyFromScreen不适用于linux,我不会感到惊讶。我会先测试一下,以确保你没有再次尝试需要System.Windows.Forms的东西。这是一个开放的测试。目前,不支持
Screen
info,因为所讨论的平台甚至可能没有屏幕。您所问的肯定不是独立于平台的。web应用程序没有屏幕。Mac窗口的概念和API与Windows非常不同。同样适用于Linux、Android和iOS。有人试图创建一个跨平台的GUI堆栈,比如Xamarin Forms或Uno PlatformIt可能会在后台使用WinApi,所以它在其他平台上不起作用,我想,对不起,我手上没有,所以不能确认/否认。它使用,所以不认为这会回答你的问题。是的,窗体通常仅在Windows上可用。
new Size
{
  Width = Screen.AllScreens.Sum(s => s.Bounds.Width),
  Height = Screen.AllScreens.Max(s => s.Bounds.Height)
}