Windows screen bounds with dual monitors

两盒软妹~` 提交于 2019-12-12 02:56:40

问题


I am looking to get the total screen resolution using dual monitors in powershell.

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

With this I get 1920 X 1200 but the resolution is actually 3840 X 1200. I could just double the resolution, however that wont always work depending on the monitors being used.

I am doing this within powershell studio. The reason for knowing this is because sometimes the program opens up off screen, if it does open off screen, I can move it back to the bottom right hand corner.


回答1:


On the primary Screen the Resolution is still 1920x1200. You can check, how much screens are attached ( [System.Windows.Forms.Screen]::AllScreens ) and work with the bounds [System.Windows.Forms.Screen]::AllScreens | select -ExpandProperty bounds.




回答2:


This is what I found works with the help of Martin. But I know it is super sloppy. I may ask another question to try to get this cleaned up.

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


来源:https://stackoverflow.com/questions/35775164/windows-screen-bounds-with-dual-monitors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!