Closing a Form from another Form

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
            diary.killForm()
            'set diary open to false
            diaryOpen = False
        End If
 
    End Sub

Open in new window

drews1fAsked:
Who is Participating?
 
David L. HansenConnect With a Mentor Programmer AnalystCommented:
I'd place your KillForm() routine in a module and have the routine accept a form as a parameter.
0
 
drews1fAuthor Commented:
ahh im new and never thought of that! but that should work!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.