[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Creating a global object for a zoom function

Posted on 2006-04-14
3
Medium Priority
?
165 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:tsay
  • 2
3 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16453317
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
0
 
LVL 5

Author Comment

by:tsay
ID: 16476412
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!
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 750 total points
ID: 16477731
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...
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

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