Solved

Global form load event

Posted on 2006-07-01
4
243 Views
Last Modified: 2010-04-23
apart from using a controlcollection in the main form and filling it up with all the forms of the project as i create them...or adding the load event in each form to a global load event as i create them...(using VB 2005 btw) is there any way to catch the application form load event...for ANY form that gets loaded?
I was hopping the application space had this event in it but it doesn't...so is there a magic fancy way of doing this in just one code without messing around with every form created?

Shorty...i'd like a global form_load event without putting any code into forms(apart from the main form if it's necessary)
0
Comment
Question by:coyotee
4 Comments
 
LVL 9

Accepted Solution

by:
noulouk earned 250 total points
ID: 17026429
Hi coyotee,

I think the best way is to create a custom and reusable form in which you can set an argument to interact with the main thread like this:

Public Class GlobalLoader

    Public Event evtNewForm(ByVal obj As Object)
   
Public Sub OnNewForm(ByVal obj As Object)
        RaiseEvent evtNewForm(obj)
        End Sub

End Class

The custom form:
Public Class CustomForm
    Inherits System.Windows.Forms.Form

gLoader As GlobalLoader
Sub New (ByVal obj As Object)
gLoader=CType(obj,GlobalLoader)
End Sub

Protected Sub CustomForm_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
        gLoader.OnNewForm("MyFormName")
End Sub
End Class

Finally in main thread, you can register the evtNewForm event to catch when a new form is loading or initializing depending on where you place the gLoader.OnNewForm("MyFormName") in your custom form.

Hope this helps.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Receiving a string from a WebService Push 21 58
Database Connections Not being returned to Connection Pool 7 33
VB.NET 2008 Publish Error 2 32
FInd Image Control Gridview 3 19
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question