TimSweet220
asked on
Close previous form
I need a quick fix piece of code that closes a window/form in a vb.net app. when the user clicks on the "save" button, the code passes parameters to the new form. I want the previous form to close at that point.
Thanks in advance.
Thanks in advance.
ASKER
2003. Separate forms.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
no it's not a start up form. I have a form (form A) that the user fills out. He clicks the "save" button and the data is saved then in the save function it makes a call the a second form.(Form B) Form A stays open (behind Form B), I want to add something to the save function in Form that closes that form after it makes the call to Form B. Basically, I don't want the user to be able to go back to Form A with out opening it again from the menu.
I think you've overcomplicated it...
In your main form, show FormA with ShowDialog().
When FormA closes, show FormB with ShowDialog().
You won't be able to interact with the main form until both forms are closed.
Something like...
Public Class YourMainForm
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fa As New FormA
fa.ShowDialog()
Dim fb As New FormB
fb.ShowDialog()
End Sub
End Class
If you need to, you can create FormB and show it via ShowDialog() from the Closing() event of FormA:
Public Class FormA
Private Sub FormA_Closing(sender As Object, e As System.ComponentModel.Canc elEventArg s) Handles MyBase.Closing
Me.Hide()
Dim fb As New FormB
fb.ShowDialog()
End Sub
End Class
Form.ShowDialog() prevents interaction with anything else until that form is closed:
http://msdn2.microsoft.com/en-us/library/c7ykbedk.aspx
In your main form, show FormA with ShowDialog().
When FormA closes, show FormB with ShowDialog().
You won't be able to interact with the main form until both forms are closed.
Something like...
Public Class YourMainForm
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fa As New FormA
fa.ShowDialog()
Dim fb As New FormB
fb.ShowDialog()
End Sub
End Class
If you need to, you can create FormB and show it via ShowDialog() from the Closing() event of FormA:
Public Class FormA
Private Sub FormA_Closing(sender As Object, e As System.ComponentModel.Canc
Me.Hide()
Dim fb As New FormB
fb.ShowDialog()
End Sub
End Class
Form.ShowDialog() prevents interaction with anything else until that form is closed:
http://msdn2.microsoft.com/en-us/library/c7ykbedk.aspx
Public Class FormA
Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
'-------Code to save data
Dim FrmFormB As New FormB
'-------If you want to pass any value to FormB
'-------Store them on a public variable which is in FormB.
'-------ex: FrmFormB.PassValue = 10
FrmFormB.Show()
Me.Close()
End Sub
End Class
Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
'-------Code to save data
Dim FrmFormB As New FormB
'-------If you want to pass any value to FormB
'-------Store them on a public variable which is in FormB.
'-------ex: FrmFormB.PassValue = 10
FrmFormB.Show()
Me.Close()
End Sub
End Class
What version VB.Net? 2005? 2003 (or below)?
What is the "owner" of the previous form? If the previous form was the "startup" form then closing it usually causes the app to close as well.
Are these standalone forms or Mdi Children?.
etc...