A little more background info on this... All my forms are set to have the ArcMap application as the parent window and are treated as singleton forms so I don't have more than on instance open at a time. The form classes are all defined in a separate module in a class called clsGlobals. Here's an example of the OnClick method of one of my tools (the "Apply Template" tool):'...in the COM class that inherits BaseCommand (i.e., a button on an ArcMap toolbar).
Public Overrides Sub OnClick()
Try
'Set pMxDoc and other variables used by multiple tools
GetMxDocumentFromArcMap(m_application)
'Make sure there are maps and layers in the document
If Not CheckFrames() Then Exit Sub
'create form and open it.
If IsNothing(clsGlobals.frmTemplate) OrElse clsGlobals.frmTemplate.IsDisposed Then
clsGlobals.frmTemplate = New TemplateForm(pMxDoc)
SetWindowLong(clsGlobals.frmTemplate.Handle.ToInt32, GWL_HWNDPARENT, pApp.hWnd)
clsGlobals.frmTemplate.Show()
Else
clsGlobals.frmTemplate.WindowState = FormWindowState.Normal
clsGlobals.frmTemplate.BringToFront()
End If
Catch ex As Exception
ExHandling(ex)
End Try
End Sub
I also added this to the code on the actual form itself, which does not seem to make a difference:Private Sub TemplateForm_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Disposed
ESRI.ArcGIS.ADF.COMSupport.AOUninitialize.Shutdown()
End Sub
Anyway, if there is a better way to implement modeless forms or if there's any important piece I'm leaving out, I'd be very grateful for your advice.