How are you creating/opening them? Since there is no forms collection in 2003 you will have to either close them manually, when tracking with public object variables, or when you close the parent form it will close the child form(s) automatically.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
U can use an arraylist containning all your opened forms and then when needed search the array to close all the unwanted forms.
U can create a module and make your array public in there for all the forms
Note also that closing your startup form will exit the application, so unless this one form you don't want to close is the startup form you're going to have to tap dance a bit to get it to work.
Because Now I remove form from Array when form is disposed:
For example:
Code:
Public Class frmEmpresas
#Region " Windows Form Designer generated code "
Private Shared frmEmpEj As frmEmpresas = Nothing
Public Shared Function Instance() As frmEmpresas
If frmEmpEj Is Nothing Then
frmEmpEj = New frmEmpresas
addForm(frmEmpEj)
End If
frmEmpEj.Focus()
Return frmEmpEj
End Function 'Instance
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
removeForm(frmEmpEj)
frmEmpEj = Nothing
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
.
.
.
End Class
But when my Main Form of the app (MDI parent form) executes this code:
Code:
Dim i As Integer
For i = 0 To formArray.Count - 1
Dim f As Form = CType(formArray(i), Form)
f.Close()
Next
formArray.Clear()
Yes, because if I remove form from Array, this have less items.
For example, If I add two forms in ArrayList, after when I executes this code:
Code:
Dim i As Integer
'array have two items
For i = 0 To formArray.Count - 1
Dim f As Form = CType(formArray(i), Form)
f.Close() 'but if close the form, this remove from ArrayList. Now ArrayList only have one item. For this it fails.
Next
formArray.Clear()
When the form is closed:
Code:
removeForm(myForm)
I hope that you have understood me, because my English is not very good.
be careful with a for loop on a dynamic size array, when the array is decreasing and i increasing, at some point i is greater than the size of the array and trying to access a value at that position in the array.
Are you using this array to store MDI Child forms? (You mentioned above that the only form remaining open is the MDI parent) If so you don't need to use an array, you should use the "MdiChildren" collection of the MDI Parent form.
Please post some of the code you need help with (it makes it easier to help you)
If your problem has been solved then please mark the thread [RESOLVED].
Don't forget to Rate this post
"Pinky, you give a whole new meaning to the phrase, 'counter-intelligence'."-The Brain-
How I want to open different instances of the same child form from other child form:
formChild1 (This one is a child form who opens other child forms)
Code:
Sub openFrm(ByVal nombre As String, ByVal accion As String, Optional ByVal id As Integer = -1)
Try
For Each forma As Form In Me.ParentForm.MdiChildren
If forma.Text = nombre Then
forma.Focus()
Exit Sub
End If
Next
fNouEmpl = New frmNouEmpl
addForm(fNouEmpl)
fNouEmpl.Tag = Guid.NewGuid().ToString
mColFrm2s.Add(fNouEmpl, fNouEmpl.Tag)
AddHandler fNouEmpl.Closed, AddressOf fNouEmpl_Closed
fNouEmpl.MdiParent = Me.MdiParent
fNouEmpl.Text = nombre
If id <> -1 Then
fNouEmpl.idEmplM = id
End If
fNouEmpl.accEmpl = accion
fNouEmpl.Show()
Catch ex As Exception
cl.shErr(ex.Message, Me.Text)
cl.controlError(Me.Text, ex.ToString)
End Try
End Sub
In the case that fNouEmpl is closed:
Code:
Private Sub fNouEmpl_Closed(ByVal sender As Object, ByVal e As System.EventArgs)
fNouEmpl.Dispose()
Me.connGrid(condicio, condicio2)
removeForm(fNouEmpl)
End Sub
If I close formChild1 before that fNouEmpl :
Code:
Private Sub frmEmpleados_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
For Each fNouEmpl In mColFrm2s
'Use this if you want to leave the frm2's open but don't want them to fire the event any more
RemoveHandler fNouEmpl.Closed, AddressOf fNouEmpl_Closed
Next
End Sub
until here runs ok.
The problem is if I close formChild1 before fNouEmpl instances, because when I close the instances of fNouEmpl, it will not call "removeForm".
Are you using this array to store MDI Child forms? (You mentioned above that the only form remaining open is the MDI parent) If so you don't need to use an array, you should use the "MdiChildren" collection of the MDI Parent form.
Please post some of the code you need help with (it makes it easier to help you)
If your problem has been solved then please mark the thread [RESOLVED].
Don't forget to Rate this post
"Pinky, you give a whole new meaning to the phrase, 'counter-intelligence'."-The Brain-