Creating a global object for a zoom function

I have a form which displays actions and a timeline for each action. On the timeline there can be a block, marking from when to when a certain action has taken place.

Now I want to create a zoom form that will pop-up when the user doubleclicks on the timeline. As you can see, the user can either doubleclick on the timeline or on a block. The zoom form showS the exact same information as the timeline, only bigger. The problem is that I need some kind of global object for this zoom form. As you have probably guessed, on the mouse_move event of the timeline and that of the block, a bunch of setfuctions have to be called on the zoomwindow.

What I do know is I create a zoomform when I create my mainform, but I don't call the show method. Then when a user doubleclicks I call the zoomform.show method. Problem is that when the user closes this form and then doubleclicks again I get an error telling me I can't access disposed objects.

Any help would be appreciated!

This is a drawing of my application:

                  TIMELINE
Actions|0      1      2      3      4      5      6      7...
------------------------------------------------------------------------------------------------
Action1|          XXXXXXXXXXX
Action2|                        XXXXXXXXXXXXXXXX
Action2|                                                    XXXXXXXXXXXXXXXXXXXXXXXXX
LVL 5
tsayAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Here is a generic answer to your problem.  Handle the Closing() event and set your global variable to Nothing:

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private WithEvents f2 As Form2

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If f2 Is Nothing Then
            f2 = New Form2
        End If
        f2.Show()
    End Sub

    Private Sub f2_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles f2.Closing
        f2 = Nothing
    End Sub

End Class
tsayAuthor Commented:
Hey Idle Mind,

I tried your solution but the same problem remains. Here's what happens:

I have a global class, called zoomfunctions and looks like this:

Public Class ZoomFunctions
    Private WithEvents frmZoom As ZoomWindow
    Public Sub CreateZoom()
        If Me.frmZoom Is Nothing Then
            Me.frmZoom = New ZoomWindow
        End If
    End Sub

    Public Sub ShowZoom()
        Me.frmZoom.Show()
    End Sub

    Public Sub SetDayToShow(ByRef plDay As Day)
        If Me.frmZoom Is Nothing Then
            MsgBox("frmzoom is nothing :(") '<= second time I get this message
        End If
        Me.frmZoom.ZoomDetail.DayToShow = plDay
    End Sub

    Public Sub SetHour(ByVal piHour As Integer)
        Me.frmZoom.ZoomDetail.Hour = piHour
    End Sub

    Private Sub frmZoom_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles frmZoom.Closing
        Me.frmZoom = Nothing
    End Sub
End Class

The CreateZoom is called when my main form loads.
The Showzoom is called when I doubleclick the object I want to zoom.
The SetDayToShow is called on the MouseOver of the object that potentially can be zoomed.
First time everything works, second time I get the Frmzoom is nothing :( message.

Tnx for the help!
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Change ShowZoom() to:

    Public Sub ShowZoom()
        If Me.frmZoom Is Nothing Then
            Me.frmZoom = New ZoomWindow
        End If
        Me.frmZoom.Show()
    End Sub

You don't need CreateZoom() then...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.