Avatar of omegaomega
omegaomega
Flag 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
Visual Basic.NET.NET Programming

Avatar of undefined
Last Comment
omegaomega

8/22/2022 - Mon
p_davis

Can you search for += to find all event hooks
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
Éric Moreau

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
omegaomega

ASKER
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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
omegaomega

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Éric Moreau

I never seen that before. I would need to experiment it to be able to see what is going on.
omegaomega

ASKER
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
omegaomega

ASKER
Problem has vanished without a clear explanation.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.