I have set up a separate script for my form elements in powershell and am using dot-sourcing to link the two together. I am calling the text box function and this function should pass the user's input back to the original script but it doesn't.
---------- First Script - being used to call ----------
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
#---------- Overall Form Config ----------#
$form = New-Object System.Windows.Forms.Form
$form.Text = "New Service Account"
$form.Size = New-Object System.Drawing.Size(300,300)
$form.StartPosition = "CenterScreen"
#---------- Account Name Field ----------#
."C:\Temp\include.ps1"
formLabel -labLocW 10 -labLocH 20 -labSizeW 280 -labSizeH 30 -labText "Enter SVC Account Name (Do Not Include SVC_)"
$a = formTextBox -tboxLocW 10 -tboxLocH 50 -tboxSizeW 260 -tboxSizeH 30
$b = formTextBox -tboxLocW 10 -tboxLocH 100 -tboxSizeW 260 -tboxSizeH 30
#$ok = formOKBut -okLocW 100 -okLocH 120 -okSizeW 60 -okSizeH 30 -okText "OK"
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Point(100,120)
$OKButton.Size = New-Object System.Drawing.Size(60,30)
$OKButton.Text = "OK"
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $OKButton
$form.Controls.Add($OKButton)
if($okbutton.Clicked){
Write-Host $a
}
#---------- Show Form ----------#
$showForm = $form.ShowDialog()
---------- Dot Script include ----------
function formTextBox($tboxLocW,$tboxLocH,$tboxSizeW,$tboxSizeH) {
$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point($tboxLocW,$tboxLocH)
$textBox.Size = New-Object System.Drawing.Size($tboxSizeW,$tboxSizeH)
$form.Controls.Add($textBox)
$output = $textBox.Text
return $output
}
$OKButton.Add_Click({Write-Host $a})?. "C:\Temp\include.ps1").