Multiple Windows Forms in Visual Studio

Tool: Visual Studio, Visual Studio Code, PSScriptPad, PowerShell Module
Version: 

Can anyone advise how to get multi-form support working in Visual Studio? I tried the techniques in another post about VS Code but it appears more needs to be done in Visual Studio to get this working.

So, looks like I may have figured it out:
When adding a new form in Visual Studio you need to remove both lines created in the Sub Form’s Form’X’.ps1 file and put that in the event handler of whatever launches the Sub Form from the Host Form.

Cut the below from the additional form:

. (Join-Path $PSScriptRoot 'SubForm.designer.ps1')
$SubForm.ShowDialog()

Add to the Host Form:

$button_OpenSubForm_Click = {
	. (Join-Path $PSScriptRoot 'SubForm.designer.ps1')
	$SubForm.ShowDialog()
}

*. (Join-Path $PSScriptRoot 'HostForm.designer.ps1')*
*$HostForm.ShowDialog()*

You also need to dot source the NewForm.ps1 file too or none of the event handler scripts get included:

$button_OpenSubForm_Click = {
	. (Join-Path $PSScriptRoot 'SubForm.designer.ps1')
	$SubForm.ShowDialog()
}

. (Join-Path $PSScriptRoot 'HostForm.designer.ps1')
. (Join-Path $PSScriptRoot 'SubForm.ps1')
$HostForm.ShowDialog()

Pulled my hair out on this one too… make sure you put the main ps1 before the “designer” ps1:

$button_OpenSubForm_Click = {
	. (Join-Path $PSScriptRoot 'SubForm.ps1') # Must be first
	. (Join-Path $PSScriptRoot 'SubForm.designer.ps1')
	$SubForm.ShowDialog()
}

# Note: Main ps1 loads first and then dot sources the designer ps1
. (Join-Path $PSScriptRoot 'HostForm.designer.ps1')

$HostForm.ShowDialog()