簡體   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