Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hi,
In certain forms I am having problems with my code. For example when I call frmTwo from frmOne, and want to close frmOne before frmTwo is shown, it does not work. I used code

(In frmOne I wrote)

Me.Dispose
frmTwo.Showdialoge()


frmOne closes but frmTwo does not appear.

If I do it otherwise,

frmTwo.Showdialoge()
Me.Dispose


In this case frmOne keeps running in the background, that I donot want.
Please advise how to manage it.

Thanks and best regards,
Furqan
Posted
Updated 12-Feb-11 7:02am
v2
Comments
Furqan Sehgal 13-Feb-11 2:29am    
Using me.close does not change the result.
Ali Al Omairi(Abu AlHassan) 13-Feb-11 18:38pm    
Sir, if you used 'frmTwo' as a modal dialog, form 'frmOne' should be kept not disposed because its the parent of 'frmOne'.

I' not quote sure, but the second code fragment looks promising so try it like this:
VB
Me.Close()
frmTwo.Showdialog()


Modification
Form.Showdialog() opens a form in modal mode. That means the code following the call of that method will not be executed until frmTwo is closed! See the MSDN documentation.
End modification

Besides that shouldn't it be Showdialog() without an e at the end and parenthesis in the method calls?

Please tell me how this went.

Cheers!
 
Share this answer
 
v6
Comments
Nish Nishant 12-Feb-11 14:07pm    
Voted 5, proposed as answer.
Manfred Rudolf Bihy 12-Feb-11 14:34pm    
Thanks!
Ali Al Omairi(Abu AlHassan) 13-Feb-11 18:50pm    
sir, I don't think that you can close a Form then execute any code after that in the same object.
The trick I found is

frmOne.Hide()
frmTwo.Showdialogue()
frmOne.Close()


Or

Just call frmTwo

frmTwo.Showdialogue()
and in its form_load event, close the first form

frmOne.Close()

This is the only workable way I found.
 
Share this answer
 
Comments
Ali Al Omairi(Abu AlHassan) 13-Feb-11 18:54pm    
Great..!!
you found you own way, Congratulations!!

100 :rose ;)
You don't need to dispose it, but close it

VB
frmTwo.Show()
Me.Close
 
Share this answer
 
v2
Comments
Nish Nishant 12-Feb-11 14:07pm    
Problem here is that ShowDialog is modal, so the parent form won't be closed until the child's dismissed.
Yusuf 12-Feb-11 14:35pm    
That is what happens when one eye is on the TV the other one on CP and the kid nagging you on the side because.....

I did update my answer, I meant to copy the OP instance name to make it clear, ended up getting everything.

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