I’ve got a partial Powershell GUI app written but I’m fairly new to Powershell and I need some help to get me on the way to having a working program. I’ve listed my code below but my questions are as follows:
I’ve set the 3rd and 4th textboxes to be read only but when I run the code these textboxes still get focus and I would like to bypass these 2 boxes and have focus set on the OK button. Can anyone tell me how to bypass focus on these two fields?
My second question has to deal with using the input data from the first two text boxes to perform a calculation and then populate values in the 3rd and 4th read only textboxes. Can anyone provide some help on this as well?
Here’s my code:
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$form = New-Object System.Windows.Forms.Form
$form.Text = ‘Data Entry Form’
$form.Size = New-Object System.Drawing.Size(300,300)
$form.StartPosition = ‘CenterScreen’
$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(75,220)
$okButton.Size = New-Object System.Drawing.Size(75,23)
$okButton.Text = ‘OK’
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $okButton
$form.Controls.Add($okButton)
$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(150,220)
$cancelButton.Size = New-Object System.Drawing.Size(75,23)
$cancelButton.Text = ‘Cancel’
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $cancelButton
$form.Controls.Add($cancelButton)
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(280,20)
$label.Text = ‘Previous Balance:’
$form.Controls.Add($label)
$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(10,40)
$textBox.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($textBox)
$label2 = New-Object System.Windows.Forms.Label
$label2.Location = New-Object System.Drawing.Point(10,70)
$label2.Size = New-Object System.Drawing.Size(280,20)
$label2.Text = ‘Current Balance:’
$form.Controls.Add($label2)
$textBox2 = New-Object System.Windows.Forms.TextBox
$textBox2.Location = New-Object System.Drawing.Point(10,90)
$textBox2.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($textBox2)
$label3 = New-Object System.Windows.Forms.Label
$label3.Location = New-Object System.Drawing.Point(10,120)
$label3.Size = New-Object System.Drawing.Size(280,20)
$label3.Text = ‘Principal Applied:’
$form.Controls.Add($label3)
$textBox3 = New-Object System.Windows.Forms.TextBox
$textBox3.Location = New-Object System.Drawing.Point(10,140)
$textBox3.Size = New-Object System.Drawing.Size(260,20)
$textbox3.ReadOnly=$true
$form.Controls.Add($textBox3)
$label4 = New-Object System.Windows.Forms.Label
$label4.Location = New-Object System.Drawing.Point(10,170)
$label4.Size = New-Object System.Drawing.Size(280,20)
$label4.Text = ‘Interest Paid:’
$form.Controls.Add($label4)
$textBox4 = New-Object System.Windows.Forms.TextBox
$textBox4.Location = New-Object System.Drawing.Point(10,190)
$textBox4.Size = New-Object System.Drawing.Size(260,20)
$textbox4.ReadOnly=$true
$form.Controls.Add($textBox4)
$form.Topmost = $true
$form.Add_Shown({$textBox.Select()})
$result = $form.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
$x = $textBox.Text
$x
}