Output Box not displaying

Welcome Forums General PowerShell Q&A Output Box not displaying

This topic contains 4 replies, has 2 voices, and was last updated by

 
Member
2 years, 9 months ago.

  • Author
    Posts
  • #37382

    Participant
    Points: 0
    Rank: Member

    Evening all

    Any reason why the below will not display in the outputbox? It's just blank with no errors

    
     function graphics {
    
    $HostName=$InputBox.text;
     
    $card = get-wmiobject Win32_VideoController -ComputerName $HostName
    $graphics = $card.caption
    $outputBoxGcard.text=$graphics }
    
    $outputBoxGcard = New-Object System.Windows.Forms.TextBox
    $outputBoxGcard.Font = "Bartclays,8"
    $outputBoxGcard.Location = New-Object System.Drawing.Size(10,210)
    $outputBoxGcard.Size = New-Object System.Drawing.Size(150,60)
    $outputBoxGcard.TextAlign = "Center"
    $outputBoxGcard.MultiLine = $True
    $HardWare.Controls.Add($outputBoxGcard)
    
    
    $ButtonMon = New-Object System.Windows.Forms.Button
    $ButtonMon.Location = New-Object System.Drawing.Size(385,180)
    $ButtonMon.Size = New-Object System.Drawing.Size(50,30)
    $ButtonMon.Text = "Monitor Sizes"
    $ButtonMon.Add_Click({$outputBoxMon.Text=""})
    $ButtonMon.Add_Click({$outputBoxGcard.Text=""})
    $ButtonMon.Add_Click({monitors})
    $ButtonMon.Add_Click({graphics})
    $Hardware.Controls.Add($ButtonMon)
    
    
  • #37384

    Member
    Points: 0
    Rank: Member

    The 4 separate event handlers for $ButtonMon.Click look a little fishy. Might be something happening with order of execution there. Try making it a single script block:

    $ButtonMon.Add_Click({
        $outputBoxMon.Text=""
        $outputBoxGcard.Text=""
        monitors
        graphics
    })
    
  • #37387

    Participant
    Points: 0
    Rank: Member

    I removed them and still no joy 🙁

  • #37396

    Participant
    Points: 0
    Rank: Member

    If i remove the "| selec caption" i get the whole property display in the output box.. So it's baffling me why just the caption won't display

  • #37398

    Member
    Points: 0
    Rank: Member

    Are you running PowerShell v2, by chance? If $card is an array, in PSv2, you'd get nothing when you tried to do $card.Caption (because arrays don't have a Caption property.) In PSv3 or later, it'll enumerate the array for you and give you the Caption properties of the elements in the array.

    To be V2 compliant with arrays, you'd do this:

    $card = get-wmiobject Win32_VideoController -ComputerName $HostName
    $graphics = $card | Select-Object -ExpandProperty Caption
    

The topic ‘Output Box not displaying’ is closed to new replies.