Results 1 to 3 of 3

Thread: Unloading forms

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    11

    Unloading forms

    Hi,

    I am a newbie to .net from VB6 (where I was a newbie to ) and am having some problems unloading forms. My program involves a lot of showing and hiding forms. It appears as though vb.net 2005 pro doesnt seem to allow the 'unload' command anymore so I was wondering how I get my hidden forms out of memory when my program exits?

    VB Code:
    1. Public Class frmLogin
    2.  
    3.     Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOk.Click
    4.  
    5.         If txtUsername.Text = "Username" And txtPassword.Text = "Password" And CbxTerms.Checked = "true" Then
    6.             Me.Visible = False
    7.             frmCat.Visible = True
    8.         ElseIf CbxTerms.Checked = "False" Then
    9.             MessageBox.Show("You must agree to the terms of use." & vbCrLf & "If you are not aware of these, please contact the network administrator.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
    10.         Else
    11.             MessageBox.Show("There was a problem with the username or password entered.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
    12.         End If
    13. End Sub
    14. End Class

    For example in this if I have a close button on my frmCat form how do I get frmLogin to Close aswell? I have tried to close() the frmLogin form instead of hide it but then the frmCat doesnt show up.

  2. #2
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: Unloading forms

    if you want to close other forms on exit from one form use:

    VB Code:
    1. Sub  Form_QueryUnload()
    2.  
    3. Unload frmlogin
    4. 'add whatever else here... use unload followed by the form name
    5. 'when the form is closed, then the other forms will be also
    6.  
    7. End sub
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  3. #3
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Unloading forms

    Seems to me it is a VB.NET 2005 question. To unload the Form, you can use
    VB Code:
    1. formName.Close()
    Quote Originally Posted by Andy123
    For example in this if I have a close button on my frmCat form how do I get frmLogin to Close aswell? I have tried to close() the frmLogin form instead of hide it but then the frmCat doesnt show up.
    Well that is a default behaviour of VB.NET Win Forms application. However you can change that behaviour by enabling the Application Framework. Open Project Properties from Project Menu and check Enable Application Framework. Then select ShutDown mode as When Last Form Closes. By selecting this option your application will remain active till you have a single form open.

    And in case you want to take a look at all the opne forms you can use My.Application.OpenForms and loop through all of them to close them one by one.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

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