2016-03-03 118 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)