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. C#
  4. Login failure needs to close main app...

Login failure needs to close main app...

Scheduled Pinned Locked Moved C#
databaseregexhelpquestion
4 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.
  • F Offline
    F Offline
    flicktom
    wrote on last edited by
    #1

    I have an MDI parent form "formMAIN" with the following code: public formMAIN() { InitializeComponent(); // blah blah blah LoginForm loginForm = new LoginForm(); loginForm.ShowDialog(); if (LoggedUserName != "") { this.Text += " [" + LoggedUserName + "]"; } else { // problem area... I want to close the main form if login failed... // IE... LoggedUserName will be "" } ... The loginForm connects to the database, checks for matching user name and password and sets the formMAIN's static variable "LoggedUserName" if a match is found. I placed it in the constructor of formMAIN so that it would appear first. I want to be able to close this main form immediately if the user closes the login form or clicks the "cancel" button on it... IE.. LoggedUserName will be blank when the focus returns to the formMAIN. I tried "this.Close();" as well as Application.Close(), but it doesn't work. I'm guessing this is because it's in the constructor for the form, which obviously is not yet completely instantiated. I can't put it in the initialize area for the same reason. I need some way to automatically perform the this.Close() operation 'after' the formMAIN completes initialization if the LoggedUserName value is still "" (IE.. failed log-in or user canceled the login form). How can this be done with the least amount of code? Flicktom -- modified at 0:23 Monday 12th December, 2005

    V P 2 Replies Last reply
    0
    • F flicktom

      I have an MDI parent form "formMAIN" with the following code: public formMAIN() { InitializeComponent(); // blah blah blah LoginForm loginForm = new LoginForm(); loginForm.ShowDialog(); if (LoggedUserName != "") { this.Text += " [" + LoggedUserName + "]"; } else { // problem area... I want to close the main form if login failed... // IE... LoggedUserName will be "" } ... The loginForm connects to the database, checks for matching user name and password and sets the formMAIN's static variable "LoggedUserName" if a match is found. I placed it in the constructor of formMAIN so that it would appear first. I want to be able to close this main form immediately if the user closes the login form or clicks the "cancel" button on it... IE.. LoggedUserName will be blank when the focus returns to the formMAIN. I tried "this.Close();" as well as Application.Close(), but it doesn't work. I'm guessing this is because it's in the constructor for the form, which obviously is not yet completely instantiated. I can't put it in the initialize area for the same reason. I need some way to automatically perform the this.Close() operation 'after' the formMAIN completes initialization if the LoggedUserName value is still "" (IE.. failed log-in or user canceled the login form). How can this be done with the least amount of code? Flicktom -- modified at 0:23 Monday 12th December, 2005

      V Offline
      V Offline
      Vikram A Punathambekar
      wrote on last edited by
      #2

      Try calling

      Environment.Exit(1);

      WARNING: I'm not sure if this is the right way to do it, but it seems to do the job. You might want to see if somebody else comes up with a better solution. Cheers, Vikram.


      "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton.

      F 1 Reply Last reply
      0
      • F flicktom

        I have an MDI parent form "formMAIN" with the following code: public formMAIN() { InitializeComponent(); // blah blah blah LoginForm loginForm = new LoginForm(); loginForm.ShowDialog(); if (LoggedUserName != "") { this.Text += " [" + LoggedUserName + "]"; } else { // problem area... I want to close the main form if login failed... // IE... LoggedUserName will be "" } ... The loginForm connects to the database, checks for matching user name and password and sets the formMAIN's static variable "LoggedUserName" if a match is found. I placed it in the constructor of formMAIN so that it would appear first. I want to be able to close this main form immediately if the user closes the login form or clicks the "cancel" button on it... IE.. LoggedUserName will be blank when the focus returns to the formMAIN. I tried "this.Close();" as well as Application.Close(), but it doesn't work. I'm guessing this is because it's in the constructor for the form, which obviously is not yet completely instantiated. I can't put it in the initialize area for the same reason. I need some way to automatically perform the this.Close() operation 'after' the formMAIN completes initialization if the LoggedUserName value is still "" (IE.. failed log-in or user canceled the login form). How can this be done with the least amount of code? Flicktom -- modified at 0:23 Monday 12th December, 2005

        P Offline
        P Offline
        Polis Pilavas
        wrote on last edited by
        #3

        Try putting your code into the form's Load() event instead. Regards, Polis Can you practice what you teach?

        1 Reply Last reply
        0
        • V Vikram A Punathambekar

          Try calling

          Environment.Exit(1);

          WARNING: I'm not sure if this is the right way to do it, but it seems to do the job. You might want to see if somebody else comes up with a better solution. Cheers, Vikram.


          "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton.

          F Offline
          F Offline
          flicktom
          wrote on last edited by
          #4

          This solution worked great. Thanks.

          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