Click here to Skip to main content
15,918,471 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Friends
i created a user control with 2 textBoxes to enter UserId and password,and a button to login.and i put it in a form for login to main form.
how to: close login form when login succeed and show main form?
thanks
Posted
Comments
[no name] 15-Sep-12 17:09pm    
form.Close() has always worked for me.
FM7 15-Sep-12 17:13pm    
where i should write this code? i have no object on form,just a user control !
[no name] 15-Sep-12 17:15pm    
You would write that code where you want the form to close. That was your question....
FM7 15-Sep-12 17:19pm    
Read the question again please.evreything i have is a buttonClick event for login button in user control.in that code i can not write: form.close()
ok?
[no name] 15-Sep-12 17:27pm    
I did read everything. The only question you asked that could be answered was "how to: close login form when login succeed and show main form?" and that answer to that question is form.Close(). No where did you mention a button click event, what database you are using (not that it matters) or anything else. You use Form.Close() to close a form. What kind of answer do you want?

Create instance and show your Login Form in your start up Form contractor. If the result wasn't successful so exit the Application or you can put it in a loop for let user to try 3 times. I write you simple one, you can write another yourself.
C#
static class Program
    {
        [STAThread]
        static void Main()
        {
            System.Windows.Forms.Application.Run(new Form1());
        }
    }


C#
public partial class Form1: Form
{
    public Form1()
    {
         loginForm _form = new loginForm();

         if (_form.ShowDialog() == DialogResult.Cancel)
             Application.Exit()

         InitializeComponent();
    }
}
 
Share this answer
 
v3
Hi,

You can create one delegate in the Usercontrol and Invoke the delegate when user is successfully login into the system.

You need to create function in main form that will close the current form. And the delegate that you have previously created will pointing to this function.

Hope i answered your question,

For referece check : Calling parent form functions from a user control[^]
 
Share this answer
 

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