Link to home
Start Free TrialLog in
Avatar of omegaomega
omegaomegaFlag for Canada

asked on

Windows Form Load event is not triggered.

I have an old mostly VB based  Windows application I have been trying to move from 32 bit systems (W2K & XP) to 64 bit systems (W7 & W10).  I am using VS2015 for this work and have the configuration set to "Any CPU".

The main form of this application inherits directly from System.Windows.Forms.Form.   When I start the application the main form's Load event handler is not called.  Other form events (e.g. Activate, Resize) are called, but as these rely on objects defined during the load event they raise appropriate null value exceptions.

I have set breakpoints in the Load event handler to confirm that it really is not being invoked.

My searches have so far yielded only results that pertain to conflicts with missing data bindings.  There are no data bindings used within this application.

Any ideas about what might cause this lack of a load event trigger will be greatly appreciated, as will suggestions about how I might further diagnose this problem.

Thanks,
Randy
Avatar of p_davis
p_davis

Can you search for += to find all event hooks
Avatar of omegaomega

ASKER

Hi, p_davis,

I'm not sure I understand the question (or I'm sure I don't know how "+=" might relate to event hooks.)  In any case however, the "+=" construct does not occur anywhere in the code for the solution.

Can you please explain further.

Thanks,
Randy
SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello, Éric,

Thanks for your note.  Yes, the "Handles Load" is there.  Missing that would certainly make it appear that the event wasn't being triggered, however this code was working fine under VS2005 on W2K and XP systems.    The full code of the event handler is below.
    Private Sub frdSupSim_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
                                                                Handles MyBase.Load
        Thread.CurrentThread.Name = "SupSim Primary"

        ' If End User Licence Agreement acceptance is required, show the splash 
        ' screen and get the user's acceptance or rejection of the agreement.
        Dim frmSplash As frdSplash = Nothing
        Try
            mdptSplashLocation = Point.Empty
            If (EULA_AcceptanceRequired()) Then
                frmSplash = New frdSplash(frdSplash.aenmSplashMode.Agreement)
                ' The EULA acceptance form will be centered on the application window. 
                ' (Because the application window is not yet in its specified location, 
                ' a reference rectangle is used for centering the EULA acceptance form.)
                Dim dreApplication As Rectangle = FormPosition(Me)
                frmSplash.StartPosition = FormStartPosition.Manual
                frmSplash.Left = dreApplication.Left + CInt((dreApplication.Width - frmSplash.Width) / 2)
                frmSplash.Top = dreApplication.Top + CInt((dreApplication.Height - frmSplash.Height) / 2)
                mdptSplashLocation = frmSplash.Location
                frmSplash.ApplicationTitle = gkstMsgAppTitle
                frmSplash.ShowDialog()
                abooAborting = (frmSplash.EULA_Accepted <> aenmTripleState.Yes) ' If the user doesn't agree, 
            End If                                                              ' abort the startup.
        Catch ex As Exception
            abooAborting = True     ' An error during user acceptance will also abort the startup.
            ReportError(ex)         ' Report unexpected errors.                 
        Finally
            If (frmSplash IsNot Nothing) Then
                frmSplash.Close()
            End If
            If (abooAborting) Then
                ' The user rejected the EULA (or an error occurred).
                Me.Close()
            End If
        End Try
        If (abooAborting) Then Exit Sub

        ' Define this as the main form so that it is easily available globally.
        gfrmMain = Me           ' GUI specific reference (type = frdSupSim).
        afrmMaster = Me         ' General reference (type = Form).

        aicnDefault = Me.Icon   ' Set the default icon for this application.
        afrmDebug = Me          '~TBR (For debugging purposes only.)
        UpdateStatusBar()       ' Clear design text from status bar.
        UpdateToolBar()

        ' Define standard object types for global reference:
        gtypUnitControlDef = GetType(clsUnitControlDef)

        ' Set form/window geometry.
        PositionForm(Me)

    End Sub

Open in new window

I think there is nothing very unusual in there.  The object gfrmMain is referenced in subsequent events (Activated and Resize) and being Null of course causes subsequent problems there.

Thanks and best regards,
Randy
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I never seen that before. I would need to experiment it to be able to see what is going on.
Nor have I.  It does seem bizarre.  

Some experimentation would be good to try to understand what happened, however I'm not even sure I could now recreate the condition.  This would require going to the most recent backup and trying to replicate the changes I may have made since then.  Sadly, I haven't the opportunity (i.e. time) at the moment for such experimentation.  Were I to encounter the problem again I would image the disks involved so I could easily return to the known (problematic) state.  That would hopefully facilitate experimentation and detailed comparison of the before and after images might provide a clue about the cause.

Cheers,
Randy
Problem has vanished without a clear explanation.