|
A simple Form application. Two Forms here, each has one button. On button click event, private void ShowForm1_Click(object sender, EventArgs e) //Form2 button click event { this.Hide(); form1.Show(); } and private void ShowForm2_Click(object sender, EventArgs e) //Form1 button click event { if (form2 == null) { form2 = new Form2(); form2.form1 = this; } this.Hide(); form2.Show(); } If i put breakpoint at this.Hide(), and wait sometime ,the form(this) will show on destop can not hide.If no breakpoint it will go well most time, and some time it is also wrong. I use vs2005 .net 2.0 on windowsXP+Sp2. And i notice that on my vista platform, the breakpoint make no effect on Show or Hide.(I donnot know if it is really ok or i do not catch the error yet) Why? |
| milex Thursday, February 21, 2008 9:24 AM |
Using the same code as the original poster, I noticed that the form wouldn't show too. However it was there, just hidden behind Visual Studio.
Can you check the task bar to make sure it isn't visible? Or if you are creating forms which don't show up in the task bar, make sure to minimize all other windows in the system. It seems you have a focus race when the different Show() methods are called. The race is between the debugger and the actual form showing up. |
| rchiodo - MSFT Wednesday, April 02, 2008 9:20 PM |
Hi, Try out this example.May be you can expand this code to solve your problem. Here I have two forms. Form1 and WelcomeForm When I run the application,if the value of x is less than 2 then I am hiding Form1 which is the parent form and loading the second form that is the WelcomeForm.In this case it will always hide Form1 and load WelcomeForm. U can replace this code to a button_click and try that too. private void Form1_Load(object sender, EventArgs e) { int x = 1; if(x<2) { this.Hide(); WelcomeForm wf = new WelcomeForm(); wf.ShowDialog(); } } Hope this helps. Cheers ... _____________________________ http://techisolutions.blogspot.com/ |
| Annamika Thursday, February 21, 2008 9:43 AM |
Thanks . Nothing changed with ur code , the form is not hide but show.
|
| milex Thursday, February 21, 2008 10:00 AM |
Oh!I am sorry to hear that.Its working perfectly here.Could you please explain me what exactly you did with the code if you dont mind? _____________________________ http://techisolutions.blogspot.com/ |
| Annamika Thursday, February 21, 2008 10:08 AM |
I'd suggest you made one form the other forms parent and if the child is shown the parent will be shown, too!? |
| KomplexoR Thursday, February 21, 2008 10:23 AM |
In debug mode , put two breakpoints on each this.Hide(), run this application and click button . So it breaks in vs , wait sometime, and use F10 process this.Hide(), you will find this form will not hide but show . If it hides ,try more times it will show.
|
| milex Thursday, February 21, 2008 10:30 AM |
I hope you are talking about your code.I thought you were working with my example code. I shall try with your code now.. Cheers.. __________________________ http://techisolutions.blogspot.com/ |
| Annamika Thursday, February 21, 2008 10:42 AM |
Hi Milex, Its working in my system.I just readjusted your code to private void ShowForm1_Click(object sender, EventArgs e) { Form1 form1 = new Form1(); this.Hide(); form1.Show(); } private void ShowForm2_Click(object sender, EventArgs e) { Form2 form2 = new Form2(); this.Hide(); form2.Show(); } Its working fine even in the way you suggested.May there is something else being wrong. Cheers.. ______________________________ http://techisolutions.blogspot.com/ |
| Annamika Thursday, February 21, 2008 10:52 AM |
Full source here: public partial class Form1 : Form { public Form2 form2=null;
public Form1() { InitializeComponent(); }
private void ShowForm2_Click(object sender, EventArgs e) { if (form2 == null) { form2 = new Form2(); form2.form1 = this; } this.Hide(); form2.Show(); } }
public partial class Form2 : Form { public Form1 form1=null;
public Form2() { InitializeComponent(); }
private void ShowForm1_Click(object sender, EventArgs e) { this.Hide(); form1.Show(); } } Try it.
|
| milex Thursday, February 21, 2008 11:07 AM |
I am not an expert coder but i have doubt on this line public Form2 form2=null; try by not giving the instance value NULL.
|
| jewelthief Thursday, February 21, 2008 1:21 PM |
Using the same code as the original poster, I noticed that the form wouldn't show too. However it was there, just hidden behind Visual Studio.
Can you check the task bar to make sure it isn't visible? Or if you are creating forms which don't show up in the task bar, make sure to minimize all other windows in the system. It seems you have a focus race when the different Show() methods are called. The race is between the debugger and the actual form showing up. |
| rchiodo - MSFT Wednesday, April 02, 2008 9:20 PM |