Click here to Skip to main content
15,921,716 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Let's say I have a form and a button in it. When I click the button I want to open the new form and start working on it. I Tried this.

C#
private void ProceedButton_Click(object sender, EventArgs e)
{
    TestCreator TestCrt = new TestCreator();
    this.Hide();
    TestCrt.ShowDialog();
    this.Close();

}


But when TestCrt is opened , it is not functioning well.
When I run TestCreator from the main its working properly but when opening by showdialog its not. For example when I click a button in TestCrt the program is shutting.
Is there another better way?
Why am I having the problem?
Posted
Updated 21-Dec-12 2:48am
v4
Comments
[no name] 21-Dec-12 8:28am    
How it could be possible..?? Place your TestCrt code here..
And ya one more thing, first you hiding the form and after showing other form, you close previous one, is there something to do such ???
missak boyajian 21-Dec-12 8:44am    
I already tried that same error. I updated the question.
[no name] 21-Dec-12 8:46am    
See my solution below...
Zoltán Zörgő 21-Dec-12 8:34am    
.Show is not modal! The this.Close(); statement is executed just after the other form is shown. If this is the main form, than you will exit the application also. Try .ShowDialog instead.
Zoltán Zörgő 21-Dec-12 8:46am    
If the problem is the same with ShowDialog, than you probably posted far to few from your code. Are you using threads for example?

After this.Close();, you exit the application because this is the main form. Try this:
C#
private void ProceedButton_Click(object sender, EventArgs e)
{
    TestCreator TestCrt = new TestCreator();
    this.Hide();
    TestCrt.ShowDialog();
    this.Close();
 
}

If you call ShowDialog, your program wait until TestCrt is closed. If you call Show, this.Close(); is called immediately, also if TestCrt isn't closed.
 
Share this answer
 
v2
C#
private void ProceedButton_Click(object sender, EventArgs e)
{
    TestCreator TestCrt = new TestCreator();
    this.Hide();
    TestCrt.Show();
    this.Close(); // remove this, because it closes the main form, that's your application exits..

}
 
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