Home All Groups Group Topic Archive Search About

How to tell when form has fully loaded

Author
17 Mar 2009 10:54 AM
Giles
Is there an event that occurs when a VB form has fully loaded and displayed?
(like the onload event in javascript)
Thanks

Author
17 Mar 2009 12:18 PM
Rick Rothstein
If I had to guess, I would say the form's Activate event would tell you
that. Put this in the (General)(Declarations) section of the form's code
window...

    Dim InitialLoad As Boolean

Put this in the form's Load event...

    InitialLoad = "True"

And use this code layout for the form's Activate event...

    Private Sub Form_Activate()
        If InitialLoad Then
            InitialLoad = False
            '
            '  Put the code you want to run after the form
            '  loads and displays for the first time here.
            '
        End If
        '
        '  Put your regular Activate event code here
        '
    End Sub

I would think the above layout should do what you want.

--
Rick (MVP - Excel)


Show quoteHide quote
"Giles" <gi***@noreply.com> wrote in message
news:eDBCF7upJHA.4540@TK2MSFTNGP04.phx.gbl...
> Is there an event that occurs when a VB form has fully loaded and
> displayed? (like the onload event in javascript)
> Thanks
>
Author
17 Mar 2009 2:45 PM
-mhd
Show quote Hide quote
"Rick Rothstein" <rick.newsNO.SPAM@NO.SPAMverizon.net> wrote:

>If I had to guess, I would say the form's Activate event would tell you
>that. Put this in the (General)(Declarations) section of the form's code
>window...
>
>    Dim InitialLoad As Boolean
>
>Put this in the form's Load event...
>
>    InitialLoad = "True"
>
>And use this code layout for the form's Activate event...
>
>    Private Sub Form_Activate()
>        If InitialLoad Then
>            InitialLoad = False
>            '
>            '  Put the code you want to run after the form
>            '  loads and displays for the first time here.
>            '
>        End If
>        '
>        '  Put your regular Activate event code here
>        '
>    End Sub
>
>I would think the above layout should do what you want.

If you have a Show command in your form load code then the Activate event will fire before
the rest of the form Load code is finished.

-mhd
Author
17 Mar 2009 3:22 PM
Jeff Johnson
"Giles" <gi***@noreply.com> wrote in message
news:eDBCF7upJHA.4540@TK2MSFTNGP04.phx.gbl...

> Is there an event that occurs when a VB form has fully loaded and
> displayed?

For some crazy reason, the Resize event does. I usually do something like
this:

Private Sub Form_Resize()
   Static fAlreadyDisplayed As Boolean

   If Not fAlreadyDisplayed Then
      ' Do all your first-time-the-form-was-displayed stuff here

      fAlreadyDisplayed = true
   End If
End Sub
Author
17 Mar 2009 3:37 PM
Nobody
Show quote Hide quote
"Jeff Johnson" <i.get@enough.spam> wrote in message
news:etaJmQxpJHA.5980@TK2MSFTNGP06.phx.gbl...
> "Giles" <gi***@noreply.com> wrote in message
> news:eDBCF7upJHA.4540@TK2MSFTNGP04.phx.gbl...
>
>> Is there an event that occurs when a VB form has fully loaded and
>> displayed?
>
> For some crazy reason, the Resize event does. I usually do something like
> this:
>
> Private Sub Form_Resize()
>   Static fAlreadyDisplayed As Boolean
>
>   If Not fAlreadyDisplayed Then
>      ' Do all your first-time-the-form-was-displayed stuff here
>
>      fAlreadyDisplayed = true
>   End If
> End Sub

I use that method too. It's documented in the help: "Resize Event: Occurs
when an object is first displayed or when the window state of an object
changes."
Author
17 Mar 2009 5:45 PM
Karl E. Peterson
Nobody wrote:
Show quoteHide quote
>>> Is there an event that occurs when a VB form has fully loaded and
>>> displayed?
>>
>> For some crazy reason, the Resize event does. I usually do something like
>> this:
>>
>> Private Sub Form_Resize()
>>   Static fAlreadyDisplayed As Boolean
>>
>>   If Not fAlreadyDisplayed Then
>>      ' Do all your first-time-the-form-was-displayed stuff here
>>
>>      fAlreadyDisplayed = true
>>   End If
>> End Sub
>
> I use that method too. It's documented in the help: "Resize Event: Occurs
> when an object is first displayed or when the window state of an object
> changes."

Yeah, but as 'mhd' pointed out, I don't think this is the answer to "fully loaded"
either, in cases where a Me.Show is used in Form_Load.  (Bad form, so to speak,
IMO.)  If you're going to do that, it's really up to you (generic "you") to trigger
whatever you need to as the last line in Form_Load, because you have already futzed
up the entire scheme of things.
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
17 Mar 2009 5:57 PM
Vinchenzo vinç
"Giles" <gi***@noreply.com> escribió en el mensaje de noticias
news:eDBCF7upJHA.4540@TK2MSFTNGP04.phx.gbl...
> Is there an event that occurs when a VB form has fully loaded and
> displayed? (like the onload event in javascript)

    No there isn't.

    If the Form is explicitly shown and any routine calls 'DoEvents' before
the 'Form_Load' ends, the Form will be fully loaded and displayed after the
last sentence of the 'Form_Load' event. Otherwise it will be fully loaded
and displayed at the first 'Form_Activate' notification:


'*****************
Public Event LoadComplete(ByVal CompletedOn As LoadCompleteConstants)

Public Enum LoadCompleteConstants
    OnActivate
    OnLoad
End Enum

Private m_Loaded  As Boolean
Private m_Activated     As Boolean

Private Sub Form_Activate()
    If m_Activated = False Then
        If m_Loaded = True Then RaiseEvent LoadComplete(OnActivate)
        m_Activated = True
    End If
    '
    '···
End Sub

Private Sub Form_Load()
    '···
    '
    If m_Activated = True Then RaiseEvent LoadComplete(OnLoad)
    m_Loaded = True
End Sub
'*****************



--
    Regards
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
( ! ) http://groups.google.com/group/microsoft.public.vb.general.discussion
( i ) http://www.microsoft.com/communities/conduct/default.mspx
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -