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. Form Loading..

Form Loading..

Scheduled Pinned Locked Moved Visual Basic
question
7 Posts 3 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

    Ok, my situation is like this. I have two forms in my application (Form1 and Form2), and on each form, I have one button (button1). I put the following code in button1 for Form1. "Dim frm2 as new Form2" "frm2.show()" and in Button1 of Form2 "Dim frm1 as new Form1" "frm1.show()" I noticed that if I clicked on these buttons a couple of times, multiple Form1 and Form2 gets created. Anyway to avoid this, like maybe when I click Form1 Button1, it closes the Form1 and opens Form2 and vice versa..?

    E B 2 Replies Last reply
    0
    • I icowa

      Ok, my situation is like this. I have two forms in my application (Form1 and Form2), and on each form, I have one button (button1). I put the following code in button1 for Form1. "Dim frm2 as new Form2" "frm2.show()" and in Button1 of Form2 "Dim frm1 as new Form1" "frm1.show()" I noticed that if I clicked on these buttons a couple of times, multiple Form1 and Form2 gets created. Anyway to avoid this, like maybe when I click Form1 Button1, it closes the Form1 and opens Form2 and vice versa..?

      E Offline
      E Offline
      enjoycrack
      wrote on last edited by
      #2

      icowa wrote: when I click Form1 Button1, it closes the Form1 and opens Form2 and vice versa I think u dont need to close form1 and open form2 and vice versa... u can let 2 forms are opened concurrently. below is just my suggestion: - In each form, u have a variable (boolean), named as isActive to store the status of the other form (this will be initialized as false, that means form2 is not activating), ie: when click form1 button1, the code should be as below: "Dim frm2 as new Form2" "if isActive then " //form2 is being actived " frm2.active()" "else " //form2 has not been showed yet "isActive = true" "frm2.show()" and certainlly, before form2 is closed, u need to set isActive = false in form1 and do the same thing for form2 << >>

      1 Reply Last reply
      0
      • I icowa

        Ok, my situation is like this. I have two forms in my application (Form1 and Form2), and on each form, I have one button (button1). I put the following code in button1 for Form1. "Dim frm2 as new Form2" "frm2.show()" and in Button1 of Form2 "Dim frm1 as new Form1" "frm1.show()" I noticed that if I clicked on these buttons a couple of times, multiple Form1 and Form2 gets created. Anyway to avoid this, like maybe when I click Form1 Button1, it closes the Form1 and opens Form2 and vice versa..?

        B Offline
        B Offline
        Briga
        wrote on last edited by
        #3

        I'm not sure if I got it correctly..... if you want to have a single form1 and form2 then the solution is not to re-declare them inside the procedure but just once at the beginning of the code. Thay way you are going to recall always the same one without creating a new instance.

        I 1 Reply Last reply
        0
        • B Briga

          I'm not sure if I got it correctly..... if you want to have a single form1 and form2 then the solution is not to re-declare them inside the procedure but just once at the beginning of the code. Thay way you are going to recall always the same one without creating a new instance.

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

          How do you go about doing that? Any help that you can offer will be greatly appreciated... Thanz

          B 1 Reply Last reply
          0
          • I icowa

            How do you go about doing that? Any help that you can offer will be greatly appreciated... Thanz

            B Offline
            B Offline
            Briga
            wrote on last edited by
            #5

            My point is to move the declaration outside the form. A way of accomplishing it could be the following. Create a module with a Sub Main (it has to be the starting sub of the project Module xyz public F1 as new Form1 public F2 as new Form2 public sub Main F1.Show while F1 is not nothing application.doevents() wend end sub and then for each form/button event private sub Button1_Click(..) F1.Hide (F2.Hide in the other form) F2.Show (F1.Show in the other form) end sub Remember to unload Form1 to end the application

            I 1 Reply Last reply
            0
            • B Briga

              My point is to move the declaration outside the form. A way of accomplishing it could be the following. Create a module with a Sub Main (it has to be the starting sub of the project Module xyz public F1 as new Form1 public F2 as new Form2 public sub Main F1.Show while F1 is not nothing application.doevents() wend end sub and then for each form/button event private sub Button1_Click(..) F1.Hide (F2.Hide in the other form) F2.Show (F1.Show in the other form) end sub Remember to unload Form1 to end the application

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

              what command do you use to unload a form?

              B 1 Reply Last reply
              0
              • I icowa

                what command do you use to unload a form?

                B Offline
                B Offline
                Briga
                wrote on last edited by
                #7

                Just issue the close method over the form. It'll be closed (passing through the closing and close events) and then destroyed.

                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