繁体   English   中英

用 .NET Core 5 确定屏幕尺寸?

[英]Determine screen size with .NET Core 5?

.NET Core如何确定屏幕尺寸? 我想按照DotNetCore Capture A Screenshot in Windows中的描述截取屏幕截图,但它们使用固定的 1920*1080 分辨率,这不适合我的目的。

我是否必须参考 System.Windows.Forms 从而被确定为 Windows?

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

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

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

评论暗示它尚不支持。

So I show you what we have done to implement it using Windows Forms (took me some time to understand how to reference Windows Forms in a .NET Core library project correctly):

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

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

然后您可以再次使用Screen class:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM