tags:

views:

322

answers:

1

I need some way of knowing when a form has finished loading. My reasoning is I have a 2nd 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 from2 are over ridden.

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.

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
        frmAllocationSearch.Activate()
    End If

End Sub
+1  A: 

Maybe you can try the Form.Activated event.

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

magnifico
I had to add a flag to prevent it being on top all the time but this was perfect.
themaninthesuitcase