Problem with Me.Dispose and Me.Close
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()</pre> 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
It sounds like frmOne is marked as your main form. To accomplish what you wish to do you might try the following...
frmOne.Hide()
frmTwo.ShowDialog()
frmOne.Close()
That code will close the first form after the second form's dialog closes. If you are simply seeking to hide the first form, and then present it again after the second form has been closed, then you will want to use the following code instead...
frmOne.Hide()
frmTwo.ShowDialog()
frmOne.Show()
In addition to what recursion posted above, my understanding is tht the .close method of a form disposes of the form as well. Second, I don't think you can call Me.Dispose (can an object commit suicide?).
I can't check this out at the moment. However, beyond this minor elaboration, recusrion is on the money with his suggestions.
精彩评论