clearing a textbox which is in a function
As commenter wrote, the function has to output the TextBox object so you can reference it later to change the text:
function InfoBox ($x,$y,$text){
$TextboxInfoBox = New-Object System.Windows.Forms.TextBox
$TextboxInfoBox.Location = New-Object System.Drawing.Size($x,$y)
$TextboxInfoBox.Size = New-Object System.Drawing.Size(200,800)
# Readonly Textbox.
$TextboxInfoBox.Enabled = $true
$TextboxInfoBox.Text = $text
$TabPanelButtons.Controls.Add($TextboxInfoBox)
$TextboxInfoBox # Output
}
Contrary to most other programming languages, in PowerShell you normally don't need to use the return
statement, except for early return from a function. Simply referring to a variable by name on its own line will output its value from the function.
Now you can store the output in a variable and change the text:
$box = Infobox -x 100 -y 150 -text 'This is the first message'
$box.Text = 'This is the second message'