Solved

Closing initial Login Form from Program.cs

Posted on 2008-10-29
3
1,704 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

688 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