Click here to Skip to main content
15,887,328 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I need to implement a login form in win form application.
My scenario is :- Login form should open first--> with correct user name and password user should be able to login--> then another page should open and login page should get closed.

Problem is:- Since log in page is the first page and it need to get put in Main() function like below.

static void Main()
{
   Application.EnableVisualStyles();
   Application.SetCompatibleTextRenderingDefault(false);
   Application.Run(new login());
}


After opening another form by formname.show() If I get exit from loginpage whole application will get exit.

Please how I can open another form without application exit and login form as my first form ?
Posted
Updated 29-Apr-19 15:28pm
v2

The easiest way is to make the login form the first form.
Then, when they have correctly logged in, create an instance of your new form, and hook into the FormClosed event.
frmMain fm = new FrmMain();
fm.FormClosed += new FormClosedEventHandler(frmMain_FormClosed);

Show the new form with Form.Show() and use Hide on your login form.
When the FormClosed event fires, your handler can either re-display the login form with Show() or exit the application.

If you set the login form ShowInTaskbar to false then no icon will appear either.

[edit]Freudian slip in the ShowInTaskbar property...[/edit]
 
Share this answer
 
v2
 
Share this answer
 
Thank you John Simmons that really worked!!!!!!!!!!:)
 
Share this answer
 
static class Program
{
    private static FrmLogin    m_FrmLogin = null; 

    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        m_FrmLogin = new FrmLogin();
        Application.Run(m_FrmLogin);
        if (m_FrmLogin.DialogResult == DialogResult.OK)
        {
            Application.Run(new FormMain());
        }
    }
}
 
Share this answer
 
Comments
Maciej Los 30-Apr-19 3:12am    
A reason of vote 1 - code has been copied from the link posted in solution #2.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900