Results 1 to 6 of 6

Thread: show a form after been closed

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Posts
    115

    show a form after been closed

    Hi All,

    This may be a simple question but it surely borthered me a lot. Ok, i have a form A as

    public frmA as new frmTypeA()


    In the program, the form A is opened by
    ....
    frmA.show
    ...

    The problem is: after the frmA is closed, i.e., user clicks the X on the right-top of the form, the frmA gets disposed. Then, when it comes to frmA.show again, a error as " can not access a disposed object frmA" is thrown out . I tried to use the following code to solve the problem but doesn't work at all

    if frmA is nothing then
    frmA = new frmTypeA()
    endif
    frmA.show()

    Any idea how to solve the problem ? I like .Net a lot , specially the OOP, shared class members, ...., etc. But under some circumstances, i miss the old VB6, the debug capability for an example.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Posts
    115
    I think i found the answer. Instead of using

    if frmA is nothing then

    should use

    if frmA.isdisposed() then

  3. #3
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Try puting this in the FormA's closing event:
    VB Code:
    1. e.Cancel = True
    2.         Me.Visible = False

    This will cancel the unload of the form, and just hide it. This means that the variable you have that points to a FormA object is still valid, and you can just set the visible property to true to show it again.

    Since FormA will stay in memory, when you are done with it for good, make sure you call it's close event.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Posts
    115
    Thanks hellswraith. I should have thought using that closing event.

  5. #5
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Why would you keep every form in memory when the user closes it?
    I don't consider that a good design.
    Just check if it has been disposed.

    I answered a similar question in this thread

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Posts
    115
    Frans C, you are right in general. But in my case, it is kind of "background" form, i.e., i don't want it to be actually closed because i want to record all the values on the form's controls and don't want to define a group of variiables to record them.

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