Results 1 to 8 of 8

Thread: When user clicks on x and then I need to reload that form

  1. #1

    Thread Starter
    Member
    Join Date
    May 2001
    Posts
    49

    Talking When user clicks on x and then I need to reload that form

    I was needing to add .hide and .shows on the form the only time now I run into the previous error is when I close the form by clicking on the x.

    1. Is there away to avoid the previous error if a user closed the form by clicking the x and then I need to reload that form again?
    If anyone can help me with this issue I would greatly appreciate it.

    Thanks to everyone on vbforums.
    The help is outstanding.

    Previous error:
    An unhandled exception of type 'System.ObjectDisposedException' occurred in system.windows.forms.dll
    Additional information: Cannot access a disposed object named "Form2".


    Thanks again for all the help.
    Dan Schuessler
    Last edited by dschuessler; Aug 20th, 2002 at 02:27 PM.

  2. #2

    Thread Starter
    Member
    Join Date
    May 2001
    Posts
    49

    Problem 1 taken care of

    When a user clicks on the x and I need to reuse that form. Is it possible to do that or not.

    or is there an easy way to take out the x from the user. I would even consider this as an option.

    Thanks so much
    Dan Schuessler
    Last edited by dschuessler; Aug 20th, 2002 at 03:30 PM.

  3. #3

    Thread Starter
    Member
    Join Date
    May 2001
    Posts
    49

    Disable the X was easy

    Sorry, I found it just set the ControlBox to False.

    However, just to be sure I'm doing this correct in vb.net is this the only way or can a user close a form with the X button and then reload that form whether it be a menu choice or a button click.

    Thanks
    Dan Schuessler

  4. #4
    Lively Member
    Join Date
    Aug 2001
    Posts
    65
    I just tested my project and i can close a second form with the x and then reload the form from a button.

    I'd say you've got some problem somewhere else thats affecting the close form event.

  5. #5

    Thread Starter
    Member
    Join Date
    May 2001
    Posts
    49

    Unhappy How did you do that.

    I get the error message:
    An unhandled exception of type 'System.ObjectDisposedException' occurred in system.windows.forms.dll - when a user clicks on the x on the second form then I click the command button again.

    Additional information: Cannot access a disposed object named "Form2".

    After I saw your post I tried a new simple app Here is what I did and I get the same message.

    I am using, form1, form2, a command buttone and a shared class. Here is the following code. I hope I am doing something wrong that can be easily corrected.

    Only code I am using is from the command button on form1 to open form2 and I am making the forms shared in a class.

    Class Code:
    Public Class cAppForms
    Public Shared appform1 As New Form1()
    Public Shared appform2 As New Form2()
    End Class

    Form1 and Comamnd Button Code:
    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    cAppForms.appform2.Show()
    End Sub
    End Class

    No Code for Form2.


    Thanks
    Dan Schuessler

  6. #6

    Thread Starter
    Member
    Join Date
    May 2001
    Posts
    49

    Thumbs up Just an update

    If I don't need the forms delcared in a class the form will close, open,reopen just fine. However, I need these forms in a class so they can be used throughout the app.

    Any thoughts.

    Thanks
    Dan Schuessler
    Last edited by dschuessler; Aug 21st, 2002 at 01:19 PM.

  7. #7

    Thread Starter
    Member
    Join Date
    May 2001
    Posts
    49

    Thumbs up Problem Solved No class or module

    I'm not sure if this is the correct way to do it in vb.net but it works.
    I just had to add this to each form.

    #Region "Upgrade Support "
    Private Shared m_vb6FormDefInstance As Form2
    Private Shared m_InitializingDefInstance As Boolean
    Public Shared Property DefInstance() As Form2
    Get
    If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
    m_InitializingDefInstance = True
    m_vb6FormDefInstance = New Form2()
    m_InitializingDefInstance = False
    End If
    DefInstance = m_vb6FormDefInstance
    End Get
    Set(ByVal Value As Form2)
    m_vb6FormDefInstance = Value
    End Set
    End Property
    #End Region

    Thanks
    Dan Schuessler

  8. #8
    Lively Member
    Join Date
    Aug 2001
    Posts
    65
    Well, you've got it working now then. I wasn't using a class for the form just the standard way thats why it was working for me then.

    Well done!

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