It will work if your goal is to briefly show the form then close it. myform is a local variable and thus will go out of scope as soon as this method ends. This will cause myform to immediately close.
You need to rethink your form handling.
You would think that would be the case...and i believe it should be... but unless this.close is closing the main application form, the newly opened form will remain open.
When you call myform.Show() it is added to the Application.OpenForms collection. Thus when the method level variable that references the form goes out of scope it doesnt close because there is still a valid reference to it in the application. It will only be disposed and garbage collected when no references to it remain.
I still prefer not to call forms this way as it feels untidy to me to have forms floating around with no "anchoring" reference, but thats my personal feelings on the matter. I always use this.Hide when i want to move from one form to the next as this allows me the option to return and works if the form to be "hidden" is the application entry point.
Reputation Points: 512
Solved Threads: 246
Nearly a Posting Virtuoso
Offline 1,260 posts
since Aug 2009