Writing output to form text box

Welcome Forums General PowerShell Q&A Writing output to form text box

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years, 2 months ago.

  • Author
  • #5284

    Points: 0
    Rank: Member

    by dcasper at 2012-11-16 07:02:39

    Hello all!

    I'm trying to figure out how to write information (write-warning, write-output, etc...) to a text box under my form inputs. I would like to use it to show important information when it processes the information thats inputted after the ok button is clicked.

    (person inputs into text box, hits OK button, function runs and processes information, and during which outputs information to text box)

    Below is snippets of my script, just to show what i have. What i need is how to output to a text box, and have it go line after line retaining the information. When new information is entered, it blanks out and starts over with the new set of inputs.


    #### Process and report

    function Process_and_report
    Do stuff here

    #### Load form

    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

    $objForm = New-Object System.Windows.Forms.Form
    $objForm.Text = "Account Termination"
    $objForm.Size = New-Object System.Drawing.Size(600,400)
    $objForm.StartPosition = "CenterScreen"

    #### Add Button

    $OKButton = New-Object System.Windows.Forms.Button
    $OKButton.Location = New-Object System.Drawing.Size(75,330)
    $OKButton.Size = New-Object System.Drawing.Size(75,23)
    $OKButton.Text = "OK"

    ### Add Input text box

    $objLabelInitials = New-Object System.Windows.Forms.Label
    $objLabelInitials.Location = New-Object System.Drawing.Size(10,40)
    $objLabelInitials.Size = New-Object System.Drawing.Size(60,20)
    $objLabelInitials.Text = "Initials:"

    $objTextBoxInitials = New-Object System.Windows.Forms.TextBox
    $objTextBoxInitials.Location = New-Object System.Drawing.Size(80,37)
    $objTextBoxInitials.Size = New-Object System.Drawing.Size(60,20)


    $objForm.Topmost = $True

    [void] $objForm.ShowDialog()

    by DonJ at 2012-11-16 09:59:06

    (As an aside, try to remember to wrap code in either the CODE or POWERSHELL tags – there are buttons on the editor toolbar for this – really helps make the code readable)

    Warnings and errors are written to separate pipelines in PowerShell. Short of writing a custom hosting app, I'm not sure there's a solid way to capture Warnings. Errors, you can trap for using a Try...Catch block and the built-in $error collection (or -ErrorVariable common parameter).

The topic ‘Writing output to form text box’ is closed to new replies.

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