close and open the same form!!!

.netdev

Member
Joined
Jan 7, 2006
Messages
10
Programming Experience
Beginner
Hey guys!

i have a form and i want to have in it a button where i want this form to close and then open the same form again
i am trying this code :

Me.Close()
Dim frmemp2 As New frmemployee
frmemp2.ShowDialog()

It is opening the form again but without exiting the first one am getting two forms while i want the forst to close and second to show...


Anu suggestions for that:confused: ???
Thanks:)
 
Moved to more appropriate forum. This is the fourth thread of yours that I've moved from the VS.NET General forum. You may be new here but you should be getting the idea by now. The VS.NET General forum is for general questions relating to the Visual Studio IDE. This question has nothing to do with the IDE so it does not belong there. Please make the small effort it takes to think about what your question relates to and post it in the most appropriate forum.

As to your issue, ShowDialog will block, i.e. not return, until the form it is called on is Closed. If you call Show instead it will retrun immediately, the current form will Close and everything will be as you want it. Note that when you call Close on a form it doesn't actually disappear until the current method completes.
 
this form is in the startup form when the form is closed the application is closed

u should make the startup object a module having a sub main() then writinin in the code to show the form when app starts.
 
I believe I can give you a maybe clearer solution if you tell me what you want the application to be doing. For example.. if your just trying to reset the controls, or if your saving on the close event and need to close it ect... I have written some property managment software in which I did sorta the same thing. I had a generic form for inputing the property info and was saving it on exit. However, I used that same form to enter the next property. There are several ways to go about this but give me a more direct need and I will give you a more propery solution to the best of my knowledge. For now I suggest using a main form and just simply declaring and opening the first form. At the same time make an event handler that catches the closed event from the form and starts a new one also adding that handle to itself.
 
This code works flawlessly. It only opens one window and when it's closed it continues to open windows. The only way to stop it is to add code in the main form to kill it. But this is what you want. Only catch is there is a base form. If you don't want a base form then use a base class or module main or somthing. Anyways this works but like I said there are many different ways to do this.

Dim WithEvents frm As Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not frm Is Nothing Then Return
frm = New Form2
AddHandler frm.Closed, AddressOf frm_Closed
frm.Show()
End Sub
Private Sub frm_Closed(ByVal sender As Object, ByVal e As System.EventArgs)
frm =
New Form2
AddHandler frm.Closed, AddressOf frm_Closed
frm.Show()
End Sub
 
Back
Top