2016-03-04 51 views
0

我正在寻找一种方法来获得双显示器的计算机上的总分辨率。我已经找到了通过this stackoverflow page(这是我的问题)做到这一点的方法,但我在下面提出的解决方案超级笨重。找到双屏幕分辨率

$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) 

输出从:

$screen = [System.Windows.Forms.Screen]::AllScreens | select -ExpandProperty bounds 

{X=1920,Y=0,Width=1920,Height=1200} {X=0,Y=0,Width=1920,Height=1200} 

所需的输出是具有总宽度和高度存储到变量。

我正在使用powershell studio。

回答

0

只要确保你初始化$屏幕宽度

$screen = [System.Windows.Forms.Screen]::AllScreens | select -ExpandProperty bounds 
$SCREENWIDTH = 0 
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 
} 

([string]$SCREENWIDTH + " " + [string]$SCREENHEIGHT)