Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all,

I have designed two forms in windows application, 1st one is "login" form and 2nd one is "Main" form. When i login successful i want to close the "login" form and i want to display the another form (Main form). How to close that when login is completed !

Thanks and Regards!
Murali
Posted

Usually that is accomplished with a login dialog, see, for instance: "C#: How to prevent main form from showing too early"[^] at Stack Overflow.
 
Share this answer
 
v2
C#
//Hide the current Form.
this.Hide();
//Created an object of GetNotificaiton From.
MainForm showNotification = new MainForm();
//show the GetnNotificaiton From.
showNotification.Show();


To show a form just write the object name dot(.) show().
like this objMainForm.Show();
 
Share this answer
 
Comments
[no name] 29-Aug-12 6:43am    
Thank you! it's working fine!..
Hello,

Solution1:
Simple way to do this is to hide the login form.

C#
private void button1_Click(object sender, EventArgs e)
       {
           Form2 obj = new Form2();
           obj.Show();
           this.Hide();
       }


Solution 2:
Modify Program.cs file

XML
static class Program
   {
       /// <summary>
       /// The main entry point for the application.
       /// </summary>
       [STAThread]
       static void Main()
       {
           Application.EnableVisualStyles();
           Application.SetCompatibleTextRenderingDefault(false);
           if (new Login().ShowDialog() != DialogResult.OK)
           {
               Application.Run(new Form2());
           }
       }
   }

Hope this will help you...
Thanks!!!
 
Share this answer
 
v3
Comments
lukeer 29-Aug-12 8:31am    
My vote of 5 completly belongs to your second solution. It's a lot clearer than the first one.
hi try this
in btnLogin click
this.Dispose();
or this.close();

try this
 
Share this answer
 
C#
private void Button1_Click(object sender,EventArgs e)
{
    this.Close();
    LoginForm lf=new LoginForm();
    lf.Show();
}
 
Share this answer
 
v3

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