Solved

Global form load event

Posted on 2006-07-01
4
244 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

749 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