OK whats is the equivelant of this code from VB 6 to VB.NET.
VB Code:
Dim frm As Form For Each frm In Forms Unload frm Set frm = Nothing Next frm
Printable View
OK whats is the equivelant of this code from VB 6 to VB.NET.
VB Code:
Dim frm As Form For Each frm In Forms Unload frm Set frm = Nothing Next frm
In .NET there is no intrinsic Forms collection so there is no real .NET version of that. Although it would be easy enough to do, just make your own forms collection. There are plenty of examples just search here or on google for 'Forms Collection'.
I did it like this -
Created global variable
Public Forms As New cFormsCollectionClass()
Then in the New of each form added this
'Add to the forms collection
Forms.Add(Me)
And in the dispose added this
'Remove all from the forms collection
Forms.Remove(Me)
Then u always know what forms are about.
Thanks for ur help. I think I am going to use this.
Application.Exit()
does Application.Exit() have the same effect as End? Because if it does, i dont want to use it.
But as its doing what I want it to for now, I wont remove it unless somone tells me its exactly the same as the End command in vb.
Thanks
there is some code posted in the vb.net codebank which i put there a while back showing how to unload all your Forms in .net, the basics of it are like this .....
the link for the thread in the codebank is this...VB Code:
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim objType As Type() = Reflection.Assembly.GetExecutingAssembly.GetTypes() Dim x As Integer, i As Integer Try For x = LBound(objType) To UBound(objType) If Not objType(x).Name = Me.Name Then '/// make sure you dont unload this form yet. i = FindWindow(vbNullString, objType(x).Name) If Not i = 0 Then PostMessage(i, CInt(&H10), vbNullString, vbNullString) End If End If Next Catch ex As Exception MessageBox.Show("Oops, the following error occured:" & ex.Message) Finally MyBase.Close() '/// now that all the other forms are closed , unload this one. End Try End Sub
Close all Forms in .Net
well?
Application.Exit() is basically the same as Ending an App with " End " ( which i recon is not good practice as it tends to terminate things abruptly )