Solved

Close previous form

Posted on 2007-03-29
6
213 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 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
Comment Utility
2003.  Separate forms.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:TimSweet220
Comment Utility
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 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now