I am trying to resize a textbox and set multiline to true when a certain option is selected within a listbox above. Weird thing is that when I right click my script, select edit, and then run it using the editor it works but when I call the file in
powershell directly on the same machine it does not. I have included the form below. Can anyone tell me what I am doing wrong?
#begin to draw forms
$Form = New-Object System.Windows.Forms.Form
$Form.Text = "Email Creator Tool"
$Form.Size = New-Object System.Drawing.Size(315,205)
$Form.StartPosition = "CenterScreen"
$Form.KeyPreview = $True
$Form.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$Form.Close()}})
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Size(5,5)
$label.Size = New-Object System.Drawing.Size(295,65)
$label.Text = "Enter the Employee ID or Username for the user you wish to make changes to. Then select the field you wish to change and enter the value in the fields below. The script will send your request to the server and you will recieve
email confirmation of changes made."
$Form.Controls.Add($label)
$label2 = New-Object System.Windows.Forms.Label
$label2.Location = New-Object System.Drawing.Size(5,72)
$label2.Size = New-Object System.Drawing.Size(75,20)
$label2.Text = "Employee ID:"
$Form.Controls.Add($label2)
$textbox = New-Object System.Windows.Forms.TextBox
$textbox.Location = New-Object System.Drawing.Size(80,72)
$textbox.Size = New-Object System.Drawing.Size(135,20)
#$textbox.Text = "Employee ID"
$Form.Controls.Add($textbox)
$label3 = New-Object System.Windows.Forms.Label
$label3.Location = New-Object System.Drawing.Size(5,92)
$label3.Size = New-Object System.Drawing.Size(75,20)
$label3.Text = "UserName:"
$Form.Controls.Add($label3)
$textbox2 = New-Object System.Windows.Forms.TextBox
$textbox2.Location = New-Object System.Drawing.Size(80,92)
$textbox2.Size = New-Object System.Drawing.Size(135,20)
#$textbox2.Text = "UserName"
$Form.Controls.Add($textbox2)
$label4 = New-Object System.Windows.Forms.Label
$label4.Location = New-Object System.Drawing.Size(5,120)
$label4.Size = New-Object System.Drawing.Size(75,20)
$label4.Text = "Field:"
$Form.Controls.Add($label4)
$listbox3 = New-Object System.Windows.Forms.listbox
$listbox3.Location = New-Object System.Drawing.Size(80,112)
$listbox3.Size = New-Object System.Drawing.Size(135,40)
[void] $ListBox3.Items.Add("Office")
[void] $ListBox3.Items.Add("Direct")
[void] $ListBox3.Items.Add("Fax")
[void] $ListBox3.Items.Add("Title")
[void] $ListBox3.Items.Add("Notes")
$ListBox3.add_SelectedIndexChanged($listbox3_SelectedIndexChanged)
$Form.Controls.Add($listbox3)
$label5 = New-Object System.Windows.Forms.Label
$label5.Location = New-Object System.Drawing.Size(5,145)
$label5.Size = New-Object System.Drawing.Size(75,20)
$label5.Text = "Value:"
$Form.Controls.Add($label5)
$textbox4 = New-Object System.Windows.Forms.TextBox
$textbox4.Location = New-Object System.Drawing.Size(80,142)
$textbox4.Size = New-Object System.Drawing.Size(135,20)
#$textbox4.Text = "Value"
$textbox4.Multiline = $false
$Form.Controls.Add($textbox4)
$listbox3_SelectedIndexChanged={
If ($listbox3.SelectedItem -eq "Notes") {
write-host Notes
$textbox4.Size = New-Object System.Drawing.Size(135,40)
$textbox4.Multiline = $true
$textbox4.refresh
$form.refresh
} Else {
write-host Not Notes
$textbox4.Size = New-Object System.Drawing.Size(135,20)
$textbox4.Multiline = $false
$textbox4.refresh
$form.refresh
}
}
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(220,70)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({create-accounts $textbox.Text $textbox2.Text $listbox3.Text $textbox4.Text;$textbox.Text="";$textbox2.Text="";$listbox3.Text="";$textbox4.Text=""})
$Form.Controls.Add($OKButton)
$Form.Topmost = $True
$Form.Add_Shown({$Form.Activate()})
[void] $Form.ShowDialog()