2016-03-03 115 views
0

我期待在PowerShell中使用雙顯示器獲得總屏幕分辨率。Windows屏幕邊界與雙顯示器

$screen = [System.Windows.Forms.Screen]::PrimaryScreen 
$SCREENWIDTH = [int]$screen.bounds.Size.Width 
$SCREENHEIGHT = [int]$screen.bounds.Size.Height 

有了這個,我得到1920×1200,但該決議實際上是3840 X 1200,我可以只需雙擊這不會始終視顯示器工作所使用的分辨率,但是。

我是在powershell studio裏面做的。知道這個的原因是因爲有時候程序在屏幕外打開,如果它關閉了屏幕,我可以將它移回到右下角。

回答

1

在主屏幕上,分辨率仍然是1920x1200。您可以檢查附加了多少屏幕([System.Windows.Forms.Screen]::AllScreens)並使用邊界[System.Windows.Forms.Screen]::AllScreens | select -ExpandProperty bounds

+0

好的,這讓我更接近。從那裏得到的結果是: {X = 1920,Y = 0,寬度= 1920,高度= 1200} {X = 0,Y = 0,寬度= 1920,高度= 1200}我會如何將它分成高度和寬度?我毫不懷疑id能夠將該字符串轉換爲我需要的格式,但它會是超級意大利麪代碼。 – user3585839

+0

用'select -expandproperty bounds'檢查我的代碼。這將創建一個包含屏幕和X,Y,高度和寬度等屬性的數組。 – Martin

0

這是我在Martin的幫助下發現的作品。但我知道這是超級馬虎。我可能會問另一個問題,試圖清理乾淨。

$screen = [System.Windows.Forms.Screen]::AllScreens | select -ExpandProperty bounds 
foreach ($item in $screen) 
{ 
    $item = $item -replace ".*Y=0,","" -replace "{", "" -replace "}", "" -replace "Width=", "" -replace "Height=", "" -replace ",", ";" 
    $pos = $item.IndexOf(";") 
    $leftPart = $item.Substring(0, $pos) 
    $rightPart = $item.Substring($pos + 1) 
    [int]$SCREENWIDTH = $SCREENWIDTH + $leftPart 
    [int]$SCREENHEIGHT = $rightPart 
} 
$richtextbox1.Text = ([string]$SCREENWIDTH + " " + [string]$SCREENHEIGHT)