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. Determining if WindowsForm is open and closing it

Determining if WindowsForm is open and closing it

Scheduled Pinned Locked Moved Visual Basic
help
6 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.
  • U Offline
    U Offline
    User 4417354
    wrote on last edited by
    #1

    I have a splitcontainer on my form. Panel1 has my menu and panel2 holds the WindowForms. If I click on my menu in panel 1 it should check if a form is loaded in panel2.If there is a form, then it closes it. Thanks for everyones help

    F W 2 Replies Last reply
    0
    • U User 4417354

      I have a splitcontainer on my form. Panel1 has my menu and panel2 holds the WindowForms. If I click on my menu in panel 1 it should check if a form is loaded in panel2.If there is a form, then it closes it. Thanks for everyones help

      F Offline
      F Offline
      freakyit
      wrote on last edited by
      #2

      hi, if you only have one form you can make the form global to access it by click on menu item.. if you have more than one form on the panel2 you need to interate through the ControlsCollection of Panel2 to determinate if one of the controls is a Form or not. greetz :)

      U 1 Reply Last reply
      0
      • F freakyit

        hi, if you only have one form you can make the form global to access it by click on menu item.. if you have more than one form on the panel2 you need to interate through the ControlsCollection of Panel2 to determinate if one of the controls is a Form or not. greetz :)

        U Offline
        U Offline
        User 4417354
        wrote on last edited by
        #3

        Thank you for your respond It will always be one form, but I need the form name or id to close it and I dont want to hardcode the forms name. I want basically: Is there a form open, if there is retrieve its id and then say id.close

        1 Reply Last reply
        0
        • U User 4417354

          I have a splitcontainer on my form. Panel1 has my menu and panel2 holds the WindowForms. If I click on my menu in panel 1 it should check if a form is loaded in panel2.If there is a form, then it closes it. Thanks for everyones help

          W Offline
          W Offline
          Wayne Gaylard
          wrote on last edited by
          #4

          What I would do is in your main form I would create a form lavel variable that returns a form i.e Private OpenForm as Form . I would assign this to the current form that is opened in the procedure that opens the form, and in the procedure that checks if a form is open you can just do this

          If Not OpenForm Is Nothing Then
          'Do Work Here
          Else
          OpenForm.Close
          End If

          Hope this helps Happy Coding

          U 1 Reply Last reply
          0
          • W Wayne Gaylard

            What I would do is in your main form I would create a form lavel variable that returns a form i.e Private OpenForm as Form . I would assign this to the current form that is opened in the procedure that opens the form, and in the procedure that checks if a form is open you can just do this

            If Not OpenForm Is Nothing Then
            'Do Work Here
            Else
            OpenForm.Close
            End If

            Hope this helps Happy Coding

            U Offline
            U Offline
            User 4417354
            wrote on last edited by
            #5

            Brilliant, thank you it's working just the way I wanted it to work.

            W 1 Reply Last reply
            0
            • U User 4417354

              Brilliant, thank you it's working just the way I wanted it to work.

              W Offline
              W Offline
              Wayne Gaylard
              wrote on last edited by
              #6

              Pleasure, glad it helped. Just be sure to make sure you set the OpenForm variable to nothing when the form is closed, else this will not work the second time. :-D Happy Coding

              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