Author Posts

September 29, 2017 at 1:47 am

I am trying to write to a textbox from a function. Can you please help me to do that.
I am not sure how this line should be >>> $Form.Controls.textbox.Text = "test" < <<<

    cls
    Function fnc_Generate_Form {

    Add-Type -AssemblyName System.Windows.Forms
    Add-Type -AssemblyName System.Drawing

    $Form = New-Object system.Windows.Forms.Form
    $Form.StartPosition = "CenterScreen"
    $Form.Topmost = $True
    $Form.size = New-Object System.Drawing.Size(200,200)
    $Form.Text = "DBA Assist"
    $Form.DataBindings.DefaultDataSourceUpdateMode = 0

    $textbox = New-Object System.Windows.Forms.TextBox
    $textbox.Location ='10,10'
    $textbox.Size = '100,100'
    $Form.Controls.Add($textbox)

    $WriteToTextBox = New-Object System.Windows.Forms.Button
    $WriteToTextBox.Location = New-Object System.Drawing.Size(35,100)
    $WriteToTextBox.Size = New-Object System.Drawing.Size(120,23)
    $WriteToTextBox.Text = "Write To TextBox"
    $Form.Controls.Add($WriteToTextBox)

    #Add Button event
    $WriteToTextBox.Add_Click(
    {
    fnc_WriteToTextBox $Form

    }
    )

    $Form.ShowDialog()
    }

    Function fnc_WriteToTextBox
    { Param($Form)

    $Form.Controls.textbox.Text = "test"

    }

    fnc_Generate_Form

September 29, 2017 at 1:58 am

Ok, So i have a solution , but hoping someone replies with something better

    Function fnc_WriteToTextBox
    { Param($Form, $textbox)

    #$Form.Controls.textbox.Text = "test"
    $textbox.Text = "test"

    }