Results 1 to 8 of 8

Thread: [RESOLVED] [2005] loading and closing problems..

  1. #1

    Thread Starter
    Addicted Member noam309's Avatar
    Join Date
    Aug 2006
    Posts
    225

    Resolved [RESOLVED] [2005] loading and closing problems..

    Hello,

    I have an application using with a lot of forms ,
    in every form there is a close button like - me.close()

    So when I run the program it shows the main form ,I push button and it shows the second form , but when I push close button in second form and it closes it , when tring to push button to execute form 2 again , it doesn't work, why?
    should I do form2 unload or something ?! I want to be able to operate form 2,3,4,5...etc , again after I closes them..

    Anyone have an idea?

    Giving an exact answer
    Saves a lot of time!!!

  2. #2
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] loading and closing problems..

    don't close the second button it desposes the form object. Insted hide it or set the visible property to false.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] loading and closing problems..

    Forms are objects. When you Close a form that was displayed using Show you destroy it, so it cannot be displayed again. If you want to display another form of the same type then you need to create another form of the same type. If you want the same form object then don't destroy it. Call Hide instead of Close. Having said that, do NOT hide the form unless you specifically need the same instance then next time you show it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Addicted Member noam309's Avatar
    Join Date
    Aug 2006
    Posts
    225

    Question Re: [2005] loading and closing problems..

    thank you both for the explanation , but if I hide or set visible.false

    it uses a lot of memory ,and I want the form not to take memory from the system while I'm not using it , what option should I choose?

    Giving an exact answer
    Saves a lot of time!!!

  5. #5
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] loading and closing problems..

    If you don't want to use memory then you need do declare the forms as New in the button click event.
    VB Code:
    1. Dim frm2 As New Form2
    2. frm2.Show()
    and than you can use
    VB Code:
    1. me.Close
    method from form2 to close the form.

  6. #6

    Thread Starter
    Addicted Member noam309's Avatar
    Join Date
    Aug 2006
    Posts
    225

    Question Re: [2005] loading and closing problems..

    Sorry about misunderstanding..

    I should write this code for whole my forms, and then to put - form2.hide
    when I want to unload the form??

    Giving an exact answer
    Saves a lot of time!!!

  7. #7
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] loading and closing problems..

    1. yes you need to use
    VB Code:
    1. Dim frm2 As New Form2
    2. frm2.Show()
    for all but form1 in the form1's OpenForm button click event.
    For the form1 you don't have to do anything but for the rest you need to declar them as New.

    2. And no, if you declare the forms as new then you need to use
    VB Code:
    1. me.Close
    from these forms close button click event. Don't hide them.

  8. #8

    Thread Starter
    Addicted Member noam309's Avatar
    Join Date
    Aug 2006
    Posts
    225

    Resolved Re: [2005] loading and closing problems..

    Got it! thank you very much!

    Giving an exact answer
    Saves a lot of time!!!

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