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. calling back a previous form..

calling back a previous form..

Scheduled Pinned Locked Moved Visual Basic
help
20 Posts 5 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.
  • I Offline
    I Offline
    icowa
    wrote on last edited by
    #1

    Need a little guidance here.. Lets say I make a new project with two forms in it, namely Form1 and Form2. Form1 is the main form and when I run my program, this is the form that comes up. In it, I make a button and upon pressing a button, it calls up form2. Here is the Command I use. Dim frmCall as New Form2 frmCall.show() when I go to form2, I create a button to close this form2 and goes back to form1. And the command in it I use is Me.Dispose() My problem is, what command do I put into this button in Form2 to call Form1 Back out.. Any help offered will be greatly appreciated.

    I C L 3 Replies Last reply
    0
    • I icowa

      Need a little guidance here.. Lets say I make a new project with two forms in it, namely Form1 and Form2. Form1 is the main form and when I run my program, this is the form that comes up. In it, I make a button and upon pressing a button, it calls up form2. Here is the Command I use. Dim frmCall as New Form2 frmCall.show() when I go to form2, I create a button to close this form2 and goes back to form1. And the command in it I use is Me.Dispose() My problem is, what command do I put into this button in Form2 to call Form1 Back out.. Any help offered will be greatly appreciated.

      I Offline
      I Offline
      icowa
      wrote on last edited by
      #2

      Oops, sorry, I put in this command in the button in Form1. Dim frmCall as New Form2 Me.Hide() ' To hide Form1 from View frmCall.show() So basically, what the button in form2 should do is, close Form2 and bring Form1 back to focus... Any help offered will be greatly appreciated.

      1 Reply Last reply
      0
      • I icowa

        Need a little guidance here.. Lets say I make a new project with two forms in it, namely Form1 and Form2. Form1 is the main form and when I run my program, this is the form that comes up. In it, I make a button and upon pressing a button, it calls up form2. Here is the Command I use. Dim frmCall as New Form2 frmCall.show() when I go to form2, I create a button to close this form2 and goes back to form1. And the command in it I use is Me.Dispose() My problem is, what command do I put into this button in Form2 to call Form1 Back out.. Any help offered will be greatly appreciated.

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        If Form1 is just hidden ( that is, if you make it not visible instead of closing it ), then you need to just show it again after the call to ShowDialog, your code in Form1 will not execute until ShowDialog ends ( that is, when Form2 is closed ). If you dispose of Form1, then it is gone, and you need to make a new one, which will not remember anything about what state your first one was left in. Christian Graus - Microsoft MVP - C++

        I 1 Reply Last reply
        0
        • C Christian Graus

          If Form1 is just hidden ( that is, if you make it not visible instead of closing it ), then you need to just show it again after the call to ShowDialog, your code in Form1 will not execute until ShowDialog ends ( that is, when Form2 is closed ). If you dispose of Form1, then it is gone, and you need to make a new one, which will not remember anything about what state your first one was left in. Christian Graus - Microsoft MVP - C++

          I Offline
          I Offline
          icowa
          wrote on last edited by
          #4

          Well, I did attempt to close Form2 but putting in a button and adding the command 'Me.Dispose()' into it. The only thing it does is close my form2 but does not bring my Form1 back out as it is still hidden somewhere. So basically my problem is how to bring the Form1 back out...

          C 1 Reply Last reply
          0
          • I icowa

            Well, I did attempt to close Form2 but putting in a button and adding the command 'Me.Dispose()' into it. The only thing it does is close my form2 but does not bring my Form1 back out as it is still hidden somewhere. So basically my problem is how to bring the Form1 back out...

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            Like I said, back out from *where* ? Did you hide Form1 ? Did you close it ? Oh - do Form1 and Form2 both define the Accept and Close behaviours for buttons ? If so, a 'feature' ( I regard it as a bug ) in .NET is that if you click abutton for Form2, and Form1 defines a button to return the same DialogResult that the button you clicked has, .NET will push Form1's button, too. So turn those properties to 'None' and always set the DialogResult yourself. However, the Show method makes a modeless dialog, doesn't it ? So you must have code further down that hides Form1. If you want to hide Form1, you're better using ShowDialog to create a modal dialog, and then you have the entry point to reshow Form1, just after ShowDialog is called. It might be best if you showed us the entire function where Form2 is created, so we know what's going on. Christian Graus - Microsoft MVP - C++

            A 1 Reply Last reply
            0
            • C Christian Graus

              Like I said, back out from *where* ? Did you hide Form1 ? Did you close it ? Oh - do Form1 and Form2 both define the Accept and Close behaviours for buttons ? If so, a 'feature' ( I regard it as a bug ) in .NET is that if you click abutton for Form2, and Form1 defines a button to return the same DialogResult that the button you clicked has, .NET will push Form1's button, too. So turn those properties to 'None' and always set the DialogResult yourself. However, the Show method makes a modeless dialog, doesn't it ? So you must have code further down that hides Form1. If you want to hide Form1, you're better using ShowDialog to create a modal dialog, and then you have the entry point to reshow Form1, just after ShowDialog is called. It might be best if you showed us the entire function where Form2 is created, so we know what's going on. Christian Graus - Microsoft MVP - C++

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

              Hmm... Dialogresult huh? I'll take a look at it... IN the mean time, I'll send u the vb.net solution to let you see and make me feel like a idiot... hahaha... I am somewhat of a beginner u see... So take a look and tell me where I went wrong... thanz...

              A C 2 Replies Last reply
              0
              • A Anonymous

                Hmm... Dialogresult huh? I'll take a look at it... IN the mean time, I'll send u the vb.net solution to let you see and make me feel like a idiot... hahaha... I am somewhat of a beginner u see... So take a look and tell me where I went wrong... thanz...

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

                Oops, can you let me have your yahoo mail or hotmail or whatever u are using so I can send it to you... thanz...

                1 Reply Last reply
                0
                • A Anonymous

                  Hmm... Dialogresult huh? I'll take a look at it... IN the mean time, I'll send u the vb.net solution to let you see and make me feel like a idiot... hahaha... I am somewhat of a beginner u see... So take a look and tell me where I went wrong... thanz...

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  Just paste the function where you create Form2 into this window, and I'll look at it. Christian Graus - Microsoft MVP - C++

                  I 1 Reply Last reply
                  0
                  • C Christian Graus

                    Just paste the function where you create Form2 into this window, and I'll look at it. Christian Graus - Microsoft MVP - C++

                    I Offline
                    I Offline
                    icowa
                    wrote on last edited by
                    #9

                    Ahhh, I think I got it. I think this is my problem. All the while I have been trying to think of the right command to put into the button on form2 to call form1 back out... Obviously you dun have to, I think.. My original Command in the button for form1 is like this. Private Sub btnDataEntry_Click(ByVal sender As Object,_ ByVal e As System.EventArgs) Handles btnDataEntry.Click Dim frmDataEntry As New DataEntry Me.Hide() frmDataEntry.Show() End Sub Taking a deep look to what you mean. I did this changes and everything works like I want it to.. Private Sub btnDataEntry_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDataEntry.Click Dim frmDataEntry As New DataEntry Me.Hide() frmDataEntry.ShowDialog() Me.Show() End Sub Alrite, now I can go ahead with my crazy project.. hehe, Thanz a lot for helping, dude... Really appreciate it lots... Until I hit another dead-end, see you around dude...

                    C D 2 Replies Last reply
                    0
                    • I icowa

                      Need a little guidance here.. Lets say I make a new project with two forms in it, namely Form1 and Form2. Form1 is the main form and when I run my program, this is the form that comes up. In it, I make a button and upon pressing a button, it calls up form2. Here is the Command I use. Dim frmCall as New Form2 frmCall.show() when I go to form2, I create a button to close this form2 and goes back to form1. And the command in it I use is Me.Dispose() My problem is, what command do I put into this button in Form2 to call Form1 Back out.. Any help offered will be greatly appreciated.

                      L Offline
                      L Offline
                      lespaul36
                      wrote on last edited by
                      #10

                      I would put a property in form2 such as public property CalledFrom(frm as Form) Get return m_Frm1 End Get Set(value as Form) m_Frm1 = value End Set Then in form1 do something such as: dim f as New Form2 f.CalledFrom = me f.Show Then in form2 call the form from the variable. m_frm.show 'or m_frm.Visible = True may work me.dispose

                      C 1 Reply Last reply
                      0
                      • I icowa

                        Ahhh, I think I got it. I think this is my problem. All the while I have been trying to think of the right command to put into the button on form2 to call form1 back out... Obviously you dun have to, I think.. My original Command in the button for form1 is like this. Private Sub btnDataEntry_Click(ByVal sender As Object,_ ByVal e As System.EventArgs) Handles btnDataEntry.Click Dim frmDataEntry As New DataEntry Me.Hide() frmDataEntry.Show() End Sub Taking a deep look to what you mean. I did this changes and everything works like I want it to.. Private Sub btnDataEntry_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDataEntry.Click Dim frmDataEntry As New DataEntry Me.Hide() frmDataEntry.ShowDialog() Me.Show() End Sub Alrite, now I can go ahead with my crazy project.. hehe, Thanz a lot for helping, dude... Really appreciate it lots... Until I hit another dead-end, see you around dude...

                        C Offline
                        C Offline
                        Christian Graus
                        wrote on last edited by
                        #11

                        No worries - glad to help. That's exactly what I thought your code must look like, and exactly what I was suggesting as a fix. ShowDialog returns an enum called 'DialogResult', that's what you'd use if you wanted to do something based on what button a user clicked to close a child dialog, for example, you'd check if it was DialogResult.OK before doing any processing, the other option being that they pressed cancel and you wanted to do nothing. It's not usual for a form to hide itself while a child form is visible - do you have a good reason to do this, in this case ? It's just not what the average user would expect, based on the behaviour of other applications. Christian Graus - Microsoft MVP - C++

                        1 Reply Last reply
                        0
                        • L lespaul36

                          I would put a property in form2 such as public property CalledFrom(frm as Form) Get return m_Frm1 End Get Set(value as Form) m_Frm1 = value End Set Then in form1 do something such as: dim f as New Form2 f.CalledFrom = me f.Show Then in form2 call the form from the variable. m_frm.show 'or m_frm.Visible = True may work me.dispose

                          C Offline
                          C Offline
                          Christian Graus
                          wrote on last edited by
                          #12

                          The main reason that this is a bad idea, is that Form2 should not be responsible for if Form1 is visible or not. It's bad OO. Christian Graus - Microsoft MVP - C++

                          I L 2 Replies Last reply
                          0
                          • C Christian Graus

                            The main reason that this is a bad idea, is that Form2 should not be responsible for if Form1 is visible or not. It's bad OO. Christian Graus - Microsoft MVP - C++

                            I Offline
                            I Offline
                            icowa
                            wrote on last edited by
                            #13

                            Hmm, well, I am not trying to make Form2 reponsible for anything. All I wanted to do is just hide Form1 for a while while I am working on form2 and when I am done with form2 and closes it, form1 will just pop back out..

                            C I 2 Replies Last reply
                            0
                            • I icowa

                              Hmm, well, I am not trying to make Form2 reponsible for anything. All I wanted to do is just hide Form1 for a while while I am working on form2 and when I am done with form2 and closes it, form1 will just pop back out..

                              I Offline
                              I Offline
                              icowa
                              wrote on last edited by
                              #14

                              But have to agree with Christian though, it does seem rather abnormal that someone would try to do something weird like that. And BTW, Lespaul, thanz for that little bit of code u suggested but sadly, I dun dig it at all... Like I mentioned, I am a new born baby VB.net programmer... Still sucking on milk, so to speak... hehehe

                              1 Reply Last reply
                              0
                              • I icowa

                                Hmm, well, I am not trying to make Form2 reponsible for anything. All I wanted to do is just hide Form1 for a while while I am working on form2 and when I am done with form2 and closes it, form1 will just pop back out..

                                C Offline
                                C Offline
                                Christian Graus
                                wrote on last edited by
                                #15

                                What you've done above is good. What this other guy suggested is bad, he wants Form2 to contain the code to show Form1. But like I said above, I don't think it's a good idea to hide Form1 necessarily, as I don't know of any other apps that do this. When you call ShowDialog, Form1 will stay visible if you let it, but it won't respond to input. Christian Graus - Microsoft MVP - C++

                                I 1 Reply Last reply
                                0
                                • C Christian Graus

                                  What you've done above is good. What this other guy suggested is bad, he wants Form2 to contain the code to show Form1. But like I said above, I don't think it's a good idea to hide Form1 necessarily, as I don't know of any other apps that do this. When you call ShowDialog, Form1 will stay visible if you let it, but it won't respond to input. Christian Graus - Microsoft MVP - C++

                                  I Offline
                                  I Offline
                                  icowa
                                  wrote on last edited by
                                  #16

                                  ohh.. i see... no point in saying what he did is good or not though, since I dun see how his code runs.. :) BTW, you guys have any idea how to implement crystal reports..?

                                  C 1 Reply Last reply
                                  0
                                  • I icowa

                                    ohh.. i see... no point in saying what he did is good or not though, since I dun see how his code runs.. :) BTW, you guys have any idea how to implement crystal reports..?

                                    C Offline
                                    C Offline
                                    Christian Graus
                                    wrote on last edited by
                                    #17

                                    I have no idea, and he won't have got an email notification. Your best bet is to google first, then if you need more info, ask a new question so people who know Crystal Reports see it and can answer it. Christian Graus - Microsoft MVP - C++

                                    I 1 Reply Last reply
                                    0
                                    • C Christian Graus

                                      I have no idea, and he won't have got an email notification. Your best bet is to google first, then if you need more info, ask a new question so people who know Crystal Reports see it and can answer it. Christian Graus - Microsoft MVP - C++

                                      I Offline
                                      I Offline
                                      icowa
                                      wrote on last edited by
                                      #18

                                      Thanz

                                      1 Reply Last reply
                                      0
                                      • I icowa

                                        Ahhh, I think I got it. I think this is my problem. All the while I have been trying to think of the right command to put into the button on form2 to call form1 back out... Obviously you dun have to, I think.. My original Command in the button for form1 is like this. Private Sub btnDataEntry_Click(ByVal sender As Object,_ ByVal e As System.EventArgs) Handles btnDataEntry.Click Dim frmDataEntry As New DataEntry Me.Hide() frmDataEntry.Show() End Sub Taking a deep look to what you mean. I did this changes and everything works like I want it to.. Private Sub btnDataEntry_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDataEntry.Click Dim frmDataEntry As New DataEntry Me.Hide() frmDataEntry.ShowDialog() Me.Show() End Sub Alrite, now I can go ahead with my crazy project.. hehe, Thanz a lot for helping, dude... Really appreciate it lots... Until I hit another dead-end, see you around dude...

                                        D Offline
                                        D Offline
                                        Dave Kreskowiak
                                        wrote on last edited by
                                        #19

                                        Small problem here. When using .ShowDialog(), it's a good idea to dispose the form when your done with it. The form holds open unmanaged resources that should be released when your done with them and not rely on the GC to do it for you whenever it gets around to it.

                                        Private Sub btnDataEntry_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDataEntry.Click
                                        Dim frmDataEntry As New DataEntry
                                        Me.Hide()
                                        frmDataEntry.ShowDialog()
                                        frmDataEntry.Dispose()
                                        Me.Show()
                                        End Sub

                                        RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                                        1 Reply Last reply
                                        0
                                        • C Christian Graus

                                          The main reason that this is a bad idea, is that Form2 should not be responsible for if Form1 is visible or not. It's bad OO. Christian Graus - Microsoft MVP - C++

                                          L Offline
                                          L Offline
                                          lespaul36
                                          wrote on last edited by
                                          #20

                                          I have had a few times when it was necessary to hide form1 and then make it visible again when form2 closed. I found that it didn't always become visible again. Probably a focus issue and I have not had to deal with that very much in vb.net. While I agree that it is a dirty way of doing it, it worked.

                                          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