?
Solved

Close previous form

Posted on 2007-03-29
6
Medium Priority
?
228 Views
Last Modified: 2013-11-25
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.

0
Comment
Question by:TimSweet220
  • 3
  • 2
6 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 18818661
We need  more info TimSweet220...

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...
0
 

Author Comment

by:TimSweet220
ID: 18819598
2003.  Separate forms.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1500 total points
ID: 18819635
And is the "startup form" one of the forms that needs to be closed?

You can simply hide the current form and show the next one using ShowDialog().

If you want to actually close (dispose) of the current form then you have to go thru alot of shenanigans...

Do you need to go in both directions?...or only "forward"?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:TimSweet220
ID: 18819730
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.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 18819806
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.CancelEventArgs) 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
0
 
LVL 3

Expert Comment

by:r1937
ID: 18839598
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
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month17 days, 8 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question