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. multiple forms

multiple forms

Scheduled Pinned Locked Moved Visual Basic
help
12 Posts 4 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.
  • M MatrixCoder

    Change the Shutdown Mode in your project properties.


    Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.

    M Offline
    M Offline
    manni_n
    wrote on last edited by
    #3

    sorry i am not able to see any option in project property window... can u explain a little bit more.....

    M 1 Reply Last reply
    0
    • M manni_n

      sorry i am not able to see any option in project property window... can u explain a little bit more.....

      M Offline
      M Offline
      MatrixCoder
      wrote on last edited by
      #4

      manni_n wrote:

      sorry i am not able to see any option in project property window...

      Are you using Visual Studio 2.0? If not, then just add Form1.close() to your close button on form2.


      Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.

      M 1 Reply Last reply
      0
      • M MatrixCoder

        manni_n wrote:

        sorry i am not able to see any option in project property window...

        Are you using Visual Studio 2.0? If not, then just add Form1.close() to your close button on form2.


        Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.

        M Offline
        M Offline
        manni_n
        wrote on last edited by
        #5

        i am using VS 2003. and about form1.close() i have already used this one, its not working telling that refernce to non shares members need object refernce... i am ussing me.close, but if i apply it on form2 then this works for form2 2 only , form1 still remains hidden..

        M 1 Reply Last reply
        0
        • M manni_n

          i am using VS 2003. and about form1.close() i have already used this one, its not working telling that refernce to non shares members need object refernce... i am ussing me.close, but if i apply it on form2 then this works for form2 2 only , form1 still remains hidden..

          M Offline
          M Offline
          MatrixCoder
          wrote on last edited by
          #6

          manni_n wrote:

          i have already used this one, its not working telling that refernce to non shares members need object refernce...

          It works fine for me. Could you post your full code for the Form2 close button?


          Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.

          M 1 Reply Last reply
          0
          • M MatrixCoder

            manni_n wrote:

            i have already used this one, its not working telling that refernce to non shares members need object refernce...

            It works fine for me. Could you post your full code for the Form2 close button?


            Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.

            M Offline
            M Offline
            manni_n
            wrote on last edited by
            #7

            there is no such great code involved in close button... i have jst used like... button2_click() me.close() end sub thats it... and if i also write form1.close then its shows the error i told u in previous post.... you do one thing just tell me your way, i'll implement that method... i just want to close all forms whenevr close button is clicked.. whether its on form2 or any other form say next form form3 or form4.

            M 1 Reply Last reply
            0
            • M manni_n

              there is no such great code involved in close button... i have jst used like... button2_click() me.close() end sub thats it... and if i also write form1.close then its shows the error i told u in previous post.... you do one thing just tell me your way, i'll implement that method... i just want to close all forms whenevr close button is clicked.. whether its on form2 or any other form say next form form3 or form4.

              M Offline
              M Offline
              MatrixCoder
              wrote on last edited by
              #8

              Alright, just to make sure, goto your project properties (Project Name Properties). Click Application, from there, you should have an option that says Shutdown Mode (or something similar). If there's no such option, then try the following: Dim x As Integer For x = 0 To (Me.OwnedForms.Length) - 1 Me.OwnedForms(x).Close() Next x


              Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.

              1 Reply Last reply
              0
              • M manni_n

                i have two forms say form1 and form2... on clicking button1 on form1 , form2 gets open... form2 has 2 two buttons back and close i have dne coding in this way: form1 : button1_click event dim a as new form2 a.show() me.hide() form2: for close button me.close() my problem is on clicking close buttton of form2, form2 gets close but form1 which is already hidden doesnt close... i want that wen i click close buttton all the hidden and active forms should close... and debugging should stop.. thanks for any kind of help.

                T Offline
                T Offline
                TwoFaced
                wrote on last edited by
                #9

                Give this a try. What I've done is added a handler for the child forms formclosed event. This way we know when the child is closed and can close too.

                Public Class Form1

                Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                    Dim a As New Form1
                    'Register our method (ChildClosed) with the new forms FormClosed event
                    AddHandler a.FormClosed, AddressOf ChildClosed
                    a.Show()
                End Sub
                
                'When the child closes this method will run which will close the current form
                Private Sub ChildClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs)
                    Me.Close()
                End Sub
                

                End Class

                ***EDIT*** Also what are you doing to go back? **EDIT2*** Oh, ya. You can also just use 'End' or 'Application.exit' to shutdown everything. I forgot about the easy answer :)

                M 1 Reply Last reply
                0
                • M manni_n

                  i have two forms say form1 and form2... on clicking button1 on form1 , form2 gets open... form2 has 2 two buttons back and close i have dne coding in this way: form1 : button1_click event dim a as new form2 a.show() me.hide() form2: for close button me.close() my problem is on clicking close buttton of form2, form2 gets close but form1 which is already hidden doesnt close... i want that wen i click close buttton all the hidden and active forms should close... and debugging should stop.. thanks for any kind of help.

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

                  The right way to do this, is to have the two forms defined as user controls and showing them both on the one form, your button changes which is visible.

                  Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                  1 Reply Last reply
                  0
                  • T TwoFaced

                    Give this a try. What I've done is added a handler for the child forms formclosed event. This way we know when the child is closed and can close too.

                    Public Class Form1

                    Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                        Dim a As New Form1
                        'Register our method (ChildClosed) with the new forms FormClosed event
                        AddHandler a.FormClosed, AddressOf ChildClosed
                        a.Show()
                    End Sub
                    
                    'When the child closes this method will run which will close the current form
                    Private Sub ChildClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs)
                        Me.Close()
                    End Sub
                    

                    End Class

                    ***EDIT*** Also what are you doing to go back? **EDIT2*** Oh, ya. You can also just use 'End' or 'Application.exit' to shutdown everything. I forgot about the easy answer :)

                    M Offline
                    M Offline
                    manni_n
                    wrote on last edited by
                    #11

                    yeah this End and application.exit are working... well to go back i am coding like this.. suppose i am on form 2 and button "back" in back_click dim a as new form1 me.close() ' to close the existing form a.show() here thing is a new form1 gets open by this method... what if i want same form1 which is hidden...?? any idea.?

                    T 1 Reply Last reply
                    0
                    • M manni_n

                      yeah this End and application.exit are working... well to go back i am coding like this.. suppose i am on form 2 and button "back" in back_click dim a as new form1 me.close() ' to close the existing form a.show() here thing is a new form1 gets open by this method... what if i want same form1 which is hidden...?? any idea.?

                      T Offline
                      T Offline
                      TwoFaced
                      wrote on last edited by
                      #12

                      You could use the same code I posted earlier. However, instead of closing form1 when the child is closed you would just show it. Form2 doesn't need to worry about form1 at all in this case. When the back button is clicked just call me.close. Form1's method will then get called because you registered that method with form2's closed event.

                      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