How to show a form, then another, then return to 1st

Goal is to fill in blanks on first form, launch folder browser (FolderBrowserDialog), select a path, process path with values from first form then return to first form.

Tried .show() and .showDialog() for first form.

If first form launched with .showDialog() the values are available for processing in FolderBrowserDialog and can be combined with selected path, but first form is gone when the FolderBrowserDialog is closed.

If first form launched with .show() then an inactive first form is displayed. Values can’t be entered in fields, the buttons aren’t active and the FolderBrowserDialog can’t be launched.

As far as I’ve gotten at this point is that
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
will always close the form, so that needs to be dropped. When that’s removed clicking the button does nothing and I haven’t been successful adding an onClick event handler to the button and make that open the FolderBrowserDialog form.

What needs to be done to make this work?

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

function call_browser {

    param ( $uId, $uName, $uCompany )
    $folder = New-Object System.Windows.Forms.FolderBrowserDialog
    $folder.Description = "Select where to save file."
    $dest = $folder.ShowDialog()

    if ($dest -eq "OK" ) 
        { 
        "This path was selected - " + '"' + $folder.SelectedPath + '"' 
        $uId; $uName; $uCompany
        } 
        else 
        { "$dest selected" } 
}

$form = New-Object System.Windows.Forms.Form
$form.Text = 'My Form'
$form.Size = New-Object System.Drawing.Size(300,270)
$form.StartPosition = 'CenterScreen'

$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(75,190)
$okButton.Size = New-Object System.Drawing.Size(75,23)
$okButton.Text = 'Select Path'
$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,190)
$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)

$labelID = New-Object System.Windows.Forms.Label
$labelID.Location = New-Object System.Drawing.Point(10,20)
$labelID.Size = New-Object System.Drawing.Size(280,20)
$labelID.Text = "ID"
$form.Controls.Add($labelID)

$textBoxID = New-Object System.Windows.Forms.TextBox
$textBoxID.Location = New-Object System.Drawing.Point(10,40)
$textBoxID.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($textBoxID)

$labelName = New-Object System.Windows.Forms.Label
$labelName.Location = New-Object System.Drawing.Point(10,70)
$labelName.Size = New-Object System.Drawing.Size(280,20)
$labelName.Text = 'Name:'
$form.Controls.Add($labelName)

$textBoxName = New-Object System.Windows.Forms.TextBox
$textBoxName.Location = New-Object System.Drawing.Point(10,90)
$textBoxName.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($textBoxName)

$labelCompany = New-Object System.Windows.Forms.Label
$labelCompany.Location = New-Object System.Drawing.Point(10,120)
$labelCompany.Size = New-Object System.Drawing.Size(280,20)
$labelCompany.Text = 'Company:'
$form.Controls.Add($labelCompany)

$textBoxCompany = New-Object System.Windows.Forms.TextBox
$textBoxCompany.Location = New-Object System.Drawing.Point(10,140)
$textBoxCompany.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($textBoxCompany)

$form.Topmost = $true

$form.Add_Shown({$textBoxID.Select()})
$result = $form.ShowDialog()

if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
    call_browser ( $textBoxID.Text, $textBoxName.Text, $textBoxCompany.Text )
}

SOLVED by reference to the following…

https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-powershell-1.0/ff730941(v=technet.10)

removed
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
(already knew that needed to go)

And instead of using
$okButton_OnClick={call_browser( $textBoxID.Text, $textBoxName.Text, $textBoxCompany.Text )}
use
$okButton.Add_Click({call_browser( $textBoxID.Text, $textBoxName.Text, $textBoxCompany.Text )})