Results 1 to 8 of 8

Thread: UNLOAD forms.

  1. #1

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    UNLOAD forms.

    OK whats is the equivelant of this code from VB 6 to VB.NET.

    VB Code:
    1. Dim frm As Form
    2.    
    3.     For Each frm In Forms
    4.         Unload frm
    5.         Set frm = Nothing
    6.     Next frm

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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'.

  3. #3
    Addicted Member
    Join Date
    Mar 2001
    Location
    Devon, UK
    Posts
    181
    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.
    Wind and waves resolves all problems.

  4. #4

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695
    Thanks for ur help. I think I am going to use this.

    Application.Exit()

  5. #5
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    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

  6. #6
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    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 .....
    VB Code:
    1. Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
    2. 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
    3.  
    4.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    5.         Dim objType As Type() = Reflection.Assembly.GetExecutingAssembly.GetTypes()
    6.         Dim x As Integer, i As Integer
    7.         Try
    8.             For x = LBound(objType) To UBound(objType)
    9.                 If Not objType(x).Name = Me.Name Then '/// make sure you dont unload this form yet.
    10.                     i = FindWindow(vbNullString, objType(x).Name)
    11.                     If Not i = 0 Then
    12.                         PostMessage(i, CInt(&H10), vbNullString, vbNullString)
    13.                     End If
    14.                 End If
    15.             Next
    16.         Catch ex As Exception
    17.             MessageBox.Show("Oops, the following error occured:" & ex.Message)
    18.         Finally
    19.             MyBase.Close() '/// now that all the other forms are closed , unload this one.
    20.         End Try
    21.     End Sub
    the link for the thread in the codebank is this...
    Close all Forms in .Net
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  7. #7
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    well?

  8. #8
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    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 )
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width