Solved

Closing initial Login Form from Program.cs

Posted on 2008-10-29
3
1,692 Views
Last Modified: 2013-12-17
Morning Experts,

I'm having a bit of a brain fart. I think there is something small that I'm missing yet need help.

So.. pretty simple scenario:
Windows form app, Login window, which should be closed once user is authorized and the actual MDI application is presented.

 I modified the Program.cs file for the Login form to be displayed before the main application comes up ( code below ).
The authentication works but the Login form doesn't go away unless I close it separately. The only way it works right now If I authenticate and then close the form by hitting the Cancel button.

Any suggestions ?
Thank you in advance.
static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
 
            Login userLogin = new Login();
 
            while (!userLogin.UserIsAuthenticated && userLogin.LoginAttempts<3)
            {
                if (userLogin.ShowDialog() == DialogResult.Cancel)
                {
                    break;
                }
            }
 
            if (userLogin.UserIsAuthenticated)
            {
                Application.Run(new Main());
            }
 
            
        }
    }

Open in new window

0
Comment
Question by:techsuppoprt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 22831348
I assume that login is a form ?

if (userLogin.UserIsAuthenticated)
            {
               Login.close();
                Application.Run(new Main());
            }
 
0
 
LVL 1

Author Comment

by:techsuppoprt
ID: 22832020
No,doesn't work.
That's the thing, it doesn't get to this "if (userLogin.UserIsAuthenticated)" block of code at all unless the form is closed or Canceled.

Any ideas ?
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 400 total points
ID: 22833133
Login userLogin = new Login();
DialogResult dr = new DialogResult ();

dr = userLogin.ShowDialog()

while (!userLogin.UserIsAuthenticated && userLogin.LoginAttempts<3 && dr.ShowDialog == DialogResult.OK)        
            {
                 userLogin.LoginAttempts++;
                 dr = userLogin.ShowDialog();
            }

if (userLogin.UserIsAuthenticated)
    Application.Run(new Main());
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question