Closing login form closing whole application? Using c# windows form.?
-
private void button1_Click(object sender, EventArgs e) { DataClasses1DataContext ddd = new DataClasses1DataContext(); var d = from c in ddd.users where textBox1.Text == c.email && textBox2.Text == c.password select c; foreach (var item in d) { if (item.email == textBox1.Text) { MessageBox.Show("correct " + item.id); Form2 f2 = new Form2(); f2.Show(); this.Close(); } } MessageBox.Show("incorrect"); } above is my code!!! can anyone explain me i'm a beginner in c#, i just want to close form1 and open form2. but it is closing whole application on closing form1 may be due to it is main form. plz tel me how to handle it, i'll be thankful if someone also tell me how can i use the data of user who enters his password in form2.
-
Answer:
When the main form closes, the application terminates. The main form is launched from Main in Program.cs like this: Application.Run(new Form1()); When Form1 closes, the Run function will return, which means Main will exit, ending the application. One way to fix it is to hide form 1 and call ShowDialog on form2. When ShowDialog returns, call Close: Form2 f2 = new Form2(); this.Hide(); f2.ShowDialog(); this.Close();
Yawar at Yahoo! Answers Visit the source
Other answers
When the main form closes, the application terminates. The main form is launched from Main in Program.cs like this: Application.Run(new Form1()); When Form1 closes, the Run function will return, which means Main will exit, ending the application. One way to fix it is to hide form 1 and call ShowDialog on form2. When ShowDialog returns, call Close: Form2 f2 = new Form2(); this.Hide(); f2.ShowDialog(); this.Close();
Ratchetr
After authenticating your username and password; form f2= new form(); this.hide(); f2.Show(); Mind you, in order to close your whole program on form f2 use; Application.Exit(); Creatively you linklabel signout to call the function. Yours in code, Dasuja.
David
Related Q & A:
- How to use login form in CakePHP?Best solution by Stack Overflow
- How to implement chat application in C# MVC?Best solution by stackoverflow.com
- How to display Login wise data in whole application?Best solution by Stack Overflow
- Is it possible to develop iPhone application using C#?Best solution by Stack Overflow
- How can I get the remote server's date and time at the client side in my application in c#?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.