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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Closing a form from a class

Closing a form from a class

Scheduled Pinned Locked Moved Visual Basic
csharpdatabasesql-servervisual-studio
3 Posts 3 Posters 1 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.
  • P Offline
    P Offline
    Pete Newman
    wrote on last edited by
    #1

    running VS ( Vb.Net ) 2005 with a lot of help from various people ive managed to cobble together a very nifty vbclass. Basicly the app im writing, logs a user into a SQl server. There is a table which controls what areas of the software the user can access, once logged in they are redirected to a blank form ( mainOptions ). MainOptions call a class which adds a button to the form for every area thay are allowed in. I can using a clickhandler in the class redirect the user to the desired area ( form ) hovever i carnt close or hide the mainOptions form ...... as the class is controlling the ClickHandler and the redirect, im tried ther following select case sender case Area1 Dim nform as new Area1_Form ** mainOptions.hide ** Area1_form . showdialog end select ive also tried mainOptions.close ive even tried calling a function back on the mainOptions form to close but it wont close down any idea's :sigh:

    I really do need help..... all this computer stuff is way over my head !!

    D M 2 Replies Last reply
    0
    • P Pete Newman

      running VS ( Vb.Net ) 2005 with a lot of help from various people ive managed to cobble together a very nifty vbclass. Basicly the app im writing, logs a user into a SQl server. There is a table which controls what areas of the software the user can access, once logged in they are redirected to a blank form ( mainOptions ). MainOptions call a class which adds a button to the form for every area thay are allowed in. I can using a clickhandler in the class redirect the user to the desired area ( form ) hovever i carnt close or hide the mainOptions form ...... as the class is controlling the ClickHandler and the redirect, im tried ther following select case sender case Area1 Dim nform as new Area1_Form ** mainOptions.hide ** Area1_form . showdialog end select ive also tried mainOptions.close ive even tried calling a function back on the mainOptions form to close but it wont close down any idea's :sigh:

      I really do need help..... all this computer stuff is way over my head !!

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

      There isn't enough information about the code to tell you definitively, but closing a form from some class isn't a good idea unless the class that's closing the form is the one that opened it in the first place. Also, you cannot close the startup form of your project. If you do, the entire application closes with it.

      Dave Kreskowiak Microsoft MVP - Visual Basic

      1 Reply Last reply
      0
      • P Pete Newman

        running VS ( Vb.Net ) 2005 with a lot of help from various people ive managed to cobble together a very nifty vbclass. Basicly the app im writing, logs a user into a SQl server. There is a table which controls what areas of the software the user can access, once logged in they are redirected to a blank form ( mainOptions ). MainOptions call a class which adds a button to the form for every area thay are allowed in. I can using a clickhandler in the class redirect the user to the desired area ( form ) hovever i carnt close or hide the mainOptions form ...... as the class is controlling the ClickHandler and the redirect, im tried ther following select case sender case Area1 Dim nform as new Area1_Form ** mainOptions.hide ** Area1_form . showdialog end select ive also tried mainOptions.close ive even tried calling a function back on the mainOptions form to close but it wont close down any idea's :sigh:

        I really do need help..... all this computer stuff is way over my head !!

        M Offline
        M Offline
        Marco Turrini
        wrote on last edited by
        #3

        First of all, let me see if I understood exactly what you meant: You have a form, which creates a class which in turns allows areas to the current user; the form draws a button for each allowed area; when the user clicks a button on the form, there's a method which opens the desired form. But - if I understood correctly - the current user clicks a button on the mainOptions form: this event has been redirected to a method of the class, but the button is on the mainOption form. What I'ld do is: - Separate logic from interface: the class should only determine if an area is allowed or not - Don't redirect the clickhandler to the class method - Use the standard clickhandler on the form: in his body, I'ld write few lines of code: define and create the appropriate areaForm, adding an handler for her Close event, show it, minimize the mainOption form (option B: hide it) - in the areaForm Close event (caveat: the areaForm_Closed event in the mainOption form), I'ld maximize the mainOptions (option B: close it) (just for clarity's sake, I baptised the mainOption form as male and the areaForm as female) And now a final, ironical touch: all my considerations are theoretical, I haven't tried them:), so there may be some buggy detail:-O; but the general idea should work:cool:. Bye

        Marco "El Turro" Turrini

        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