Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Open/Close Forms: Has anybody seen this problem?

Open/Close Forms: Has anybody seen this problem?

Scheduled Pinned Locked Moved Visual Basic
helpquestion
12 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brad Fackrell
    wrote on last edited by
    #1

    I show/hide different forms by defining the forms in a module:

    Public Class formLibrary

    Public Shared frmMain As Form
    Public Shared frmComponents As Form
    Public Shared frmNewProject As Form
    ....
    

    End Class

    Then I use the following to close the current form and open another:

     Dim newFrmMain As New frmMain
     formLibrary.frmNewProject.Hide()
     newFrmMain.ShowDialog()
    

    This is working perfect for all forms in my project except one. When I attempt to open the frmNewProject, I get this error:

    An unhandled exception of type 'System.NullReferenceException' occurred in Mule! Data Management Tool.exe
    Additional information: Object reference not set to an instance of an object.

    ..on this line of code: formLibrary.frmNewProject.Hide() Has anybody ever experienced a problem like this? Thanks Brad

    A 1 Reply Last reply
    0
    • B Brad Fackrell

      I show/hide different forms by defining the forms in a module:

      Public Class formLibrary

      Public Shared frmMain As Form
      Public Shared frmComponents As Form
      Public Shared frmNewProject As Form
      ....
      

      End Class

      Then I use the following to close the current form and open another:

       Dim newFrmMain As New frmMain
       formLibrary.frmNewProject.Hide()
       newFrmMain.ShowDialog()
      

      This is working perfect for all forms in my project except one. When I attempt to open the frmNewProject, I get this error:

      An unhandled exception of type 'System.NullReferenceException' occurred in Mule! Data Management Tool.exe
      Additional information: Object reference not set to an instance of an object.

      ..on this line of code: formLibrary.frmNewProject.Hide() Has anybody ever experienced a problem like this? Thanks Brad

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      Your form declaration is this: Public **Shared** frmNewProject As Form And you recieve an unhandled exception here: formLibrary.frmNewProject.Hide() The reason is because .Hide is not a shared sub procedure of the Forms Class, therefore you are required to instantiate a Form object instance. For instance: Public frmNewProject As **New** Form

      A B 2 Replies Last reply
      0
      • A Anonymous

        Your form declaration is this: Public **Shared** frmNewProject As Form And you recieve an unhandled exception here: formLibrary.frmNewProject.Hide() The reason is because .Hide is not a shared sub procedure of the Forms Class, therefore you are required to instantiate a Form object instance. For instance: Public frmNewProject As **New** Form

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        In other words, when you trying to hide a form that does not exist in memory :doh:

        1 Reply Last reply
        0
        • A Anonymous

          Your form declaration is this: Public **Shared** frmNewProject As Form And you recieve an unhandled exception here: formLibrary.frmNewProject.Hide() The reason is because .Hide is not a shared sub procedure of the Forms Class, therefore you are required to instantiate a Form object instance. For instance: Public frmNewProject As **New** Form

          B Offline
          B Offline
          Brad Fackrell
          wrote on last edited by
          #4

          Thanks. That works (anyway it gets me through the code with no exception). But now frmNewProject does not hide. I can't select it but it is still visible. Any ideas? Thanks Brad

          A 1 Reply Last reply
          0
          • B Brad Fackrell

            Thanks. That works (anyway it gets me through the code with no exception). But now frmNewProject does not hide. I can't select it but it is still visible. Any ideas? Thanks Brad

            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            Do you have a code sample of what you have changed and how you are using .Hide? And what do you mean when you say Brad Fackrell wrote: I can't select it but it is still visible.

            B 1 Reply Last reply
            0
            • A Anonymous

              Do you have a code sample of what you have changed and how you are using .Hide? And what do you mean when you say Brad Fackrell wrote: I can't select it but it is still visible.

              B Offline
              B Offline
              Brad Fackrell
              wrote on last edited by
              #6

              The class is where my forms are declared:

              Public Class formLibrary

              Public Shared frmOpenProject As New Form
              Public Shared frmMain As Form
              Public Shared frmScoringJustification As New Form
              Public Shared frmProjectName As New Form
              Public Shared frmDatesAndLocation As New Form
              Public Shared frmPOC As New Form
              Public Shared frmArticulation As New Form
              Public Shared frmCollectorsAndNotes As New Form
              Public Shared frmComponents As New Form
              Public Shared frmPrint As New Form
              Public Shared frmNewProject As New Form
              

              End Class

              The code that I use to Hide and Show:

              Dim newFrmMain As New frmMain
              formLibrary.frmNewProject.Hide()
              newFrmMain.ShowDialog()

              When I execute this, frmMain loads and is active. frmNewProject is still visible (behind frmMain, frmMain is a small form; about 30% of the screen) but I cannot select it or any of it's controls. Thanks for your help.

              A 1 Reply Last reply
              0
              • B Brad Fackrell

                The class is where my forms are declared:

                Public Class formLibrary

                Public Shared frmOpenProject As New Form
                Public Shared frmMain As Form
                Public Shared frmScoringJustification As New Form
                Public Shared frmProjectName As New Form
                Public Shared frmDatesAndLocation As New Form
                Public Shared frmPOC As New Form
                Public Shared frmArticulation As New Form
                Public Shared frmCollectorsAndNotes As New Form
                Public Shared frmComponents As New Form
                Public Shared frmPrint As New Form
                Public Shared frmNewProject As New Form
                

                End Class

                The code that I use to Hide and Show:

                Dim newFrmMain As New frmMain
                formLibrary.frmNewProject.Hide()
                newFrmMain.ShowDialog()

                When I execute this, frmMain loads and is active. frmNewProject is still visible (behind frmMain, frmMain is a small form; about 30% of the screen) but I cannot select it or any of it's controls. Thanks for your help.

                A Offline
                A Offline
                Anonymous
                wrote on last edited by
                #7

                I'm not quite sure why your frmNewProject would still be visible...but the reason why you cannot select it or any of it's controls is because you are showing your frmMain as modal. Brad Fackrell wrote: newFrmMain.ShowDialog() When you use .ShowDialog, you are displaying your form modal, meaning you can not access any other form until you close your frmMain. Going back to your frmNewProject, where are you showing the form in code? If .Hide is not used, is it possible to .Close the form? Just to make sure it is accessing that line of code. I did a quick test with your class and placed a .Show and .Hide in two button events. It worked with no problems...so in theory, it should be working for you?

                B 1 Reply Last reply
                0
                • A Anonymous

                  I'm not quite sure why your frmNewProject would still be visible...but the reason why you cannot select it or any of it's controls is because you are showing your frmMain as modal. Brad Fackrell wrote: newFrmMain.ShowDialog() When you use .ShowDialog, you are displaying your form modal, meaning you can not access any other form until you close your frmMain. Going back to your frmNewProject, where are you showing the form in code? If .Hide is not used, is it possible to .Close the form? Just to make sure it is accessing that line of code. I did a quick test with your class and placed a .Show and .Hide in two button events. It worked with no problems...so in theory, it should be working for you?

                  B Offline
                  B Offline
                  Brad Fackrell
                  wrote on last edited by
                  #8

                  Anonymous wrote: where are you showing the form in code? I have a btnClick that calls:

                  Dim newFrmMain As New frmMain
                  formLibrary.frmNewProject.Hide()
                  newFrmMain.ShowDialog()

                  ...nothing else in the btnClick sub. Anonymous wrote: If .Hide is not used, is it possible to .Close the form? No. I think it goes back to what you said about newFrmMain.ShowDialog() only allowing newFrmMain to be accessable. In fact, after removing formLibrary.frmNewProject.Hide(), it seems like that line of code is doing absolutely nothing. I've gone through frmNewProject with a "fine tooth comb" to see if there is anything that could be making it 'hang'...no luck finding anything.

                  A 1 Reply Last reply
                  0
                  • B Brad Fackrell

                    Anonymous wrote: where are you showing the form in code? I have a btnClick that calls:

                    Dim newFrmMain As New frmMain
                    formLibrary.frmNewProject.Hide()
                    newFrmMain.ShowDialog()

                    ...nothing else in the btnClick sub. Anonymous wrote: If .Hide is not used, is it possible to .Close the form? No. I think it goes back to what you said about newFrmMain.ShowDialog() only allowing newFrmMain to be accessable. In fact, after removing formLibrary.frmNewProject.Hide(), it seems like that line of code is doing absolutely nothing. I've gone through frmNewProject with a "fine tooth comb" to see if there is anything that could be making it 'hang'...no luck finding anything.

                    A Offline
                    A Offline
                    Anonymous
                    wrote on last edited by
                    #9

                    Try commenting out the newFrmMain.ShowDialog()...does your code execute the formLibrary.frmNewProject.Hide()? Give the debugger a try as well, and step into that line of code. It should be executing. Also, where did you place the code to display the frmNewProject form? (formLibrary.frmNewProject.Show())? I am assuming you did show the frmNewProject...otherwise, the line formLibrary.frmNewProject.Hide() will execute, but you won't have a form to hide, therefore appearing like it did absolutely nothing.

                    B 1 Reply Last reply
                    0
                    • A Anonymous

                      Try commenting out the newFrmMain.ShowDialog()...does your code execute the formLibrary.frmNewProject.Hide()? Give the debugger a try as well, and step into that line of code. It should be executing. Also, where did you place the code to display the frmNewProject form? (formLibrary.frmNewProject.Show())? I am assuming you did show the frmNewProject...otherwise, the line formLibrary.frmNewProject.Hide() will execute, but you won't have a form to hide, therefore appearing like it did absolutely nothing.

                      B Offline
                      B Offline
                      Brad Fackrell
                      wrote on last edited by
                      #10

                      Anonymous wrote: Try commenting out the newFrmMain.ShowDialog()...does your code execute the formLibrary.frmNewProject.Hide() No. It stays visible and active. Anonymous wrote: Give the debugger a try as well It appears to execute just like any other .Hide that is working properly. The debugger doesn't do much at that line. Is there something specific that I can look for? Anonymous wrote: where did you place the code to display the frmNewProject form? (formLibrary.frmNewProject.Show())? In the form that is displayed prior to frmNewProject I have a btnClick with this:

                      Dim newFrmNewProject As New frmNewProject
                      formLibrary.frmOpenProject.Hide()
                      newFrmNewProject.ShowDialog()

                      Strange thing that I have noticed, after executing the btnClick to hide frmNewProject and show frmMain, I can close frmMain using the 'X' in the upper right hand corner (frmMain_Closed) but the application stays running and frmNewProject is once again active.

                      A 1 Reply Last reply
                      0
                      • B Brad Fackrell

                        Anonymous wrote: Try commenting out the newFrmMain.ShowDialog()...does your code execute the formLibrary.frmNewProject.Hide() No. It stays visible and active. Anonymous wrote: Give the debugger a try as well It appears to execute just like any other .Hide that is working properly. The debugger doesn't do much at that line. Is there something specific that I can look for? Anonymous wrote: where did you place the code to display the frmNewProject form? (formLibrary.frmNewProject.Show())? In the form that is displayed prior to frmNewProject I have a btnClick with this:

                        Dim newFrmNewProject As New frmNewProject
                        formLibrary.frmOpenProject.Hide()
                        newFrmNewProject.ShowDialog()

                        Strange thing that I have noticed, after executing the btnClick to hide frmNewProject and show frmMain, I can close frmMain using the 'X' in the upper right hand corner (frmMain_Closed) but the application stays running and frmNewProject is once again active.

                        A Offline
                        A Offline
                        Anonymous
                        wrote on last edited by
                        #11

                        Brad Fackrell wrote: Dim newFrmNewProject As New frmNewProject formLibrary.frmOpenProject.Hide() newFrmNewProject.ShowDialog() Does this code work in the form displayed prior to frmNewProject?? If that works, then you have a very strange situation as it is the exact same code when you are attempting to display your newFrmMain. But...I think the problem is the following: In your class code you have: Public Class formLibrary Public Shared frmOpenProject As New Form Public Shared frmMain As Form Public Shared frmScoringJustification As New Form Public Shared frmProjectName As New Form Public Shared frmDatesAndLocation As New Form Public Shared frmPOC As New Form Public Shared frmArticulation As New Form Public Shared frmCollectorsAndNotes As New Form Public Shared frmComponents As New Form Public Shared frmPrint As New Form **Public Shared frmNewProject As New Form** End Class Take note of the bold line in your class. Then in your btnClick event you placed: Dim newFrmMain As New frmMain **formLibrary.frmNewProject.Hide()** newFrmMain.ShowDialog() Again take note of the bold. Then in your previous form when you display your frmNewProject you had: **Dim newFrmNewProject As New frmNewProject** formLibrary.frmOpenProject.Hide() **newFrmNewProject.ShowDialog()** Now if I am correct, when you are attempting to hide your frmNewProject using this line of code (in your btnClick): **formLibrary.frmNewProject.Hide()** It is executing...BUT it is hiding the frmNewProject in your fromLibrary class...which hasn't actually been displayed to the user. Thus appearing to do abosulutely nothing. How does that work? You are creating a new (local) instance of frmNewProject and then using the .ShowDialog to display it. So, you can test my theory by changing what you had in your previous code: **Dim newFrmNewProject As New frmNewProject** formLibrary.frmOpenProject.Hide() **newFrmNewProject.ShowDialog()** Try changing it to: 'Dim newFrmNewProject As New frmNewProject **formLibrary.frmNewProject.ShowDialog()** 'newFrmNewProject.ShowDialog() I know I jumped around alot...but the main idea is that in your code you are attempting to .Hide a form that hasn't actually been displayed to the user. This is because the formLibrary.frmNewProject and newFrmNewProject are two diffe

                        B 1 Reply Last reply
                        0
                        • A Anonymous

                          Brad Fackrell wrote: Dim newFrmNewProject As New frmNewProject formLibrary.frmOpenProject.Hide() newFrmNewProject.ShowDialog() Does this code work in the form displayed prior to frmNewProject?? If that works, then you have a very strange situation as it is the exact same code when you are attempting to display your newFrmMain. But...I think the problem is the following: In your class code you have: Public Class formLibrary Public Shared frmOpenProject As New Form Public Shared frmMain As Form Public Shared frmScoringJustification As New Form Public Shared frmProjectName As New Form Public Shared frmDatesAndLocation As New Form Public Shared frmPOC As New Form Public Shared frmArticulation As New Form Public Shared frmCollectorsAndNotes As New Form Public Shared frmComponents As New Form Public Shared frmPrint As New Form **Public Shared frmNewProject As New Form** End Class Take note of the bold line in your class. Then in your btnClick event you placed: Dim newFrmMain As New frmMain **formLibrary.frmNewProject.Hide()** newFrmMain.ShowDialog() Again take note of the bold. Then in your previous form when you display your frmNewProject you had: **Dim newFrmNewProject As New frmNewProject** formLibrary.frmOpenProject.Hide() **newFrmNewProject.ShowDialog()** Now if I am correct, when you are attempting to hide your frmNewProject using this line of code (in your btnClick): **formLibrary.frmNewProject.Hide()** It is executing...BUT it is hiding the frmNewProject in your fromLibrary class...which hasn't actually been displayed to the user. Thus appearing to do abosulutely nothing. How does that work? You are creating a new (local) instance of frmNewProject and then using the .ShowDialog to display it. So, you can test my theory by changing what you had in your previous code: **Dim newFrmNewProject As New frmNewProject** formLibrary.frmOpenProject.Hide() **newFrmNewProject.ShowDialog()** Try changing it to: 'Dim newFrmNewProject As New frmNewProject **formLibrary.frmNewProject.ShowDialog()** 'newFrmNewProject.ShowDialog() I know I jumped around alot...but the main idea is that in your code you are attempting to .Hide a form that hasn't actually been displayed to the user. This is because the formLibrary.frmNewProject and newFrmNewProject are two diffe

                          B Offline
                          B Offline
                          Brad Fackrell
                          wrote on last edited by
                          #12

                          Yes, that makes sense. I appreciate all of your help on this. Brad

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups