Inconsistent screen.bounds

Welcome Forums General PowerShell Q&A Inconsistent screen.bounds

This topic contains 1 reply, has 1 voice, and was last updated by

11 months, 1 week ago.

  • Author
  • #96392

    Points: 64
    Rank: Member

    Using the below code provided by Will on here when I run it from the ISE I get one set of valus for the screen.bounds but when running from the console or via scheduled task I get a different set of values. The one I get from the ISE are correct and the form fills the second monitor.. Any ideas why I get different values ?

    #region screenblocker
    Add-Type -AssemblyName System.Windows.Forms
    $screens = [System.Windows.Forms.Screen]::Allscreens | Where-Object Primary -eq $false
    $synchash.screens = New-Object System.Collections.Generic.List[System.Object]
    foreach($screen in $screens){
    foreach ($screen in $screens){
    $synchash."$($screen.devicename.replace('\',").replace('.',"))" = $screen
    $newRunspace =[runspacefactory]::CreateRunspace()
    $newRunspace.ApartmentState = "STA"
    $newRunspace.ThreadOptions = "ReuseThread"
    $PowerShell = [PowerShell]::Create().AddScript({
    function LoadXaml ($filename){
    $XamlLoader=(New-Object System.Xml.XmlDocument)
    return $XamlLoader
    $screenNum = $synchash.screens[0]
    $display = "Display" + $screenNum

    $XamlMainWindow = LoadXaml("\blankScreen.xaml")
    $reader = (New-Object System.Xml.XmlNodeReader $XamlMainWindow)
    $syncHash."Window$screenNum" = [Windows.Markup.XamlReader]::Load($reader)

    [xml]$XAML = $XamlMainWindow
    $XamlMainWindow.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object{
    #Find all of the form types and add them as members to the synchash
    $syncHash.Add($("" + $_.Name + $screenNum),$syncHash."Window$screenNum".FindName($_.Name) )

    $syncHash."Window$screenNum".Top = $synchash.$display.bounds.Top;
    $syncHash."Window$screenNum".Left = $synchash.$display.bounds.Left;
    $syncHash."Window$screenNum".Width = $synchash.$display.bounds.Width;
    $syncHash."Window$screenNum".Height = $synchash.$display.bounds.Height;

    $synchash."error$screenNum" = $error
    $PowerShell.Runspace = $newRunspace
    PowerShell = $PowerShell
    Runspace = $PowerShell.BeginInvoke()
    #endregion screenblocker

  • #96407

    Points: 64
    Rank: Member

    A further bit of investigating

    If I run [System.Windows.Forms.Screen]::Allscreens in the ISE it returns details on both my primary and secondary monitors, however if I run it in the console it only returns details of my primary monitor. How can I get details of the secondary monitor in the console ?

The topic ‘Inconsistent screen.bounds’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort