VB.NET .NET after load event?

13,960

Solution 1

Maybe you can try the Form.Activated event.

Occurs when the form is activated in code or by the user.

Solution 2

You may want to try the Forms 'Shown' Event

Share:
13,960
themaninthesuitcase
Author by

themaninthesuitcase

Updated on June 09, 2022

Comments

  • themaninthesuitcase
    themaninthesuitcase almost 2 years

    I need some way of knowing when a form has finished loading. My reasoning is I have a second form that is loaded when this form loads. The code for this is called from form1.load.

    Form2 is currently being displayed behind form1 as I am guessing form1 calls an activate or similar at the end of the load so any Activate, BringToFront, etc. calls on form2 are overridden.

    If you look at the code below, I have tried adding frmAllocationSearch.Activate, frmAllocationSearch.BringToFront and Me.SendToBack after the call to ShowAlloactionSearchDialog(), but these are all wasted as something is happening after the load event is fired to bring Me to the front.

    The code is:

    Private Sub Allocation_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
                                Handles Me.Load
    
        ShowAlloactionSearchDialog()
    End Sub
    
    Private Sub ShowAlloactionSearchDialog()
    
        If frmAllocationSearch Is Nothing OrElse frmAllocationSearch.IsDisposed Then
            frmAllocationSearch = New AllocationSearch
            frmAllocationSearch.MdiParent = Me.MdiParent
            frmAllocationSearch.Info = Me.Info
            frmAllocationSearch.Top = Me.Top
            frmAllocationSearch.Left = Me.Left + Me.Width - frmAllocationSearch.Width
            frmAllocationSearch.AllocationWindow = Me
    
            frmAllocationSearch.Show()
        Else
            If frmAllocationSearch.WindowState = FormWindowState.Minimized Then
                frmAllocationSearch.WindowState = FormWindowState.Normal
            End IF
            frmAllocationSearch.Activate()
        End If
    End Sub
    
  • themaninthesuitcase
    themaninthesuitcase about 14 years
    I had to add a flag to prevent it being on top all the time but this was perfect.
  • htm11h
    htm11h about 8 years
    This event is still in the initialization process. The Form is not fully loaded when this event is called.