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. Changing the Active Forms

Changing the Active Forms

Scheduled Pinned Locked Moved Visual Basic
8 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.
  • N Offline
    N Offline
    neha12
    wrote on last edited by
    #1

    By dafault form1 is the active form . How can we change the active form to form 2 such that after closing form1 our application wont be closed. neha

    D 1 Reply Last reply
    0
    • N neha12

      By dafault form1 is the active form . How can we change the active form to form 2 such that after closing form1 our application wont be closed. neha

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

      Are you saying that you'll have multiple forms open at the same time and that the user can close any of them and still keep the app running? Sounds like a job for seperate apps to me but I don't know all the details about what your doing... Ummm...You might want to try having either a Main function that declares and shows all the forms, or you might want to do the same thing in a hidden form. You can then go into the Project Properties and change the startup object to either Main or the hidden form. Now, you'r also going to have to handle the Close events of these forms so your Main or hidden form knows that all of your visible forms are closed so it knows when to quit. RageInTheMachine9532

      N 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Are you saying that you'll have multiple forms open at the same time and that the user can close any of them and still keep the app running? Sounds like a job for seperate apps to me but I don't know all the details about what your doing... Ummm...You might want to try having either a Main function that declares and shows all the forms, or you might want to do the same thing in a hidden form. You can then go into the Project Properties and change the startup object to either Main or the hidden form. Now, you'r also going to have to handle the Close events of these forms so your Main or hidden form knows that all of your visible forms are closed so it knows when to quit. RageInTheMachine9532

        N Offline
        N Offline
        neha12
        wrote on last edited by
        #3

        Thanks for the reply , but in my appln there are 7 forms & once I start executing the appln , My main startup form appears. ok. Now once I go from this startup form to form2 , I would like to close the startup form(form1). when I close the startup form (form1) then my application gets closed. So for this can u suggest any remedy so that I can transfer the active control from form1(startup) to form2 & can close startup form??

        D 1 Reply Last reply
        0
        • N neha12

          Thanks for the reply , but in my appln there are 7 forms & once I start executing the appln , My main startup form appears. ok. Now once I go from this startup form to form2 , I would like to close the startup form(form1). when I close the startup form (form1) then my application gets closed. So for this can u suggest any remedy so that I can transfer the active control from form1(startup) to form2 & can close startup form??

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

          Then you might want to try something like Me.Hide() on your main form. Or Form1.Hide() when you enter the Activate code on Form2. RageInTheMachine9532

          N 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Then you might want to try something like Me.Hide() on your main form. Or Form1.Hide() when you enter the Activate code on Form2. RageInTheMachine9532

            N Offline
            N Offline
            neha12
            wrote on last edited by
            #5

            Currently Iam doing that only but then when Iam closing the main form ie form2 then my application is not getting closed. ie I am required to go to the close button from the VB menu to stop execution of the application. I dont know how far u can understand what I mean to say !!

            D 2 Replies Last reply
            0
            • N neha12

              Currently Iam doing that only but then when Iam closing the main form ie form2 then my application is not getting closed. ie I am required to go to the close button from the VB menu to stop execution of the application. I dont know how far u can understand what I mean to say !!

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

              Now it sounds like your first form is a splash screen. What ever form is your startup form CANNOT be closed unless you want your entire app to be closed with it. Your startup form does NOT have to be visible when you app starts. You can start your app with Form1.Visible=False and have it Form2.Show, Form3.Show, whatever... But! You have to keep track of which Forms are open in your main form (Form1) and determine when Form1 either shows itself to be closed or closes on its own. RageInTheMachine9532

              1 Reply Last reply
              0
              • N neha12

                Currently Iam doing that only but then when Iam closing the main form ie form2 then my application is not getting closed. ie I am required to go to the close button from the VB menu to stop execution of the application. I dont know how far u can understand what I mean to say !!

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

                I think there is a problem with your design assumptions and how Windows Forms apps work. It would appears that you think your application can stay open so long as there is ANY form in your app open:

                          Application
                               |
                               |
                

                +-------+-------+-------+-------+
                | | | | |
                Form1 Form2 Form3 Form4 Form5

                This is just not the case. Your application depends on a main class, or Form, that is the central hub of your application. Something like this:

                          Application
                               |
                             Form1
                               |
                

                +-------+-------+-------+-------+
                | | | | |
                Form2 Form3 Form4 Form5 Form6
                | |
                Form7 Form8

                Only when Form1 is closed can your application close, and in opposite terms, only so long as Form1 is open, even if its not visible, can your app stay open. In the latter example, Form2 can be your splash screen, Forms 3-6 can be options dialogs, editors, print previews, subsections of your app, whatever, ... But in all cases, Form1 MUST keep track of which forms are open and closed. RageInTheMachine9532

                N 1 Reply Last reply
                0
                • D Dave Kreskowiak

                  I think there is a problem with your design assumptions and how Windows Forms apps work. It would appears that you think your application can stay open so long as there is ANY form in your app open:

                            Application
                                 |
                                 |
                  

                  +-------+-------+-------+-------+
                  | | | | |
                  Form1 Form2 Form3 Form4 Form5

                  This is just not the case. Your application depends on a main class, or Form, that is the central hub of your application. Something like this:

                            Application
                                 |
                               Form1
                                 |
                  

                  +-------+-------+-------+-------+
                  | | | | |
                  Form2 Form3 Form4 Form5 Form6
                  | |
                  Form7 Form8

                  Only when Form1 is closed can your application close, and in opposite terms, only so long as Form1 is open, even if its not visible, can your app stay open. In the latter example, Form2 can be your splash screen, Forms 3-6 can be options dialogs, editors, print previews, subsections of your app, whatever, ... But in all cases, Form1 MUST keep track of which forms are open and closed. RageInTheMachine9532

                  N Offline
                  N Offline
                  neha12
                  wrote on last edited by
                  #8

                  Thanks :) ,, Thanks a lot .. My doubt is completely cleared... Thanks for explaining it so nicely ... Now I will implement this in my application. If I have any doubts later then again I will write back.

                  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