Closing a Form from another Form

Posted on 2008-11-12
Last Modified: 2012-05-05
I have an application with 2 panels.
Left panel contains navigation and the right panel contains a toolstrip on which MDI tabs are placed.

I want to allow the user to open as many windows as they want with the only limitation being they can only open ONE of each.

So when Btn1 is pressed for example i check a boolean to see if its open or not. If it is it tells its already open and cant be opened twice, if not it opens. thats easy.

My problem is disposing of each form and clearing the resources. I have added a sub to each form called KillForm() which disposes of everything on each form. But how can i call this sub from the mainForm? this is my code so far attached below.

This wont work because diary doesnt exist as a form when im writing my code. Is there anyway around this?
Private Sub TabStrip1_TabRemoved(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabStrip1.TabRemoved

        If TabStrip1.SelectedTab.Text = "My Diary " Then

            'dispose of all objects and close form


            'set diary open to false

            diaryOpen = False

        End If

    End Sub

Open in new window

Question by:drews1f
    LVL 15

    Accepted Solution

    I'd place your KillForm() routine in a module and have the routine accept a form as a parameter.

    Author Comment

    ahh im new and never thought of that! but that should work!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Suggested Solutions

    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    737 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

    20 Experts available now in Live!

    Get 1:1 Help Now