Click here to Skip to main content
14,326,871 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

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]
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

   
Rate this:
Please Sign up or sign in to vote.

Solution 3

Thank you John Simmons that really worked!!!!!!!!!!:)
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

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());
        }
    }
}
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100