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
Gain unlimited access to on-demand training courses with an Experts Exchange subscription.Get Access
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE
Connect with Certified Experts to gain insight and support on specific technology challenges including: