Public Sub CloseForms(ByVal WhichForm As String) Dim FormList As New List(Of Control) Dim FormCnt As Integer = FormList.Count - 1 For Each frm As Form In getMyControls(FormList, frmMain.flpMain, GetType(Form)) Select Case WhichForm Case "First" If FormList.Item(0) Is frm Then frm.Close() Case "Last" If FormList.Item(FormCnt) Is frm Then frm.Close() Case "All" frm.Close() End Select Next GC.Collect() End Sub
Public Function getMyControls(ByVal ControlList As List(Of Control), ByVal parent As Control, ByVal ControlType As System.Type) As List(Of Control) If parent Is Nothing Then Return ControlList For Each child As Control In parent.Controls Try ControlList.Add(child) Catch End Try Next child Return ControlList End Function
ion was unhandled
Message=Object reference not set to an instance of an object.
with the line
For Each frm As Form In getMyControls(FormList, frmMain.flpMain, GetType(Form))
, but that method doesn't find any children either.
For Each frm As Form In Main.MdiChildren.AsEnumerable
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.