Solved

Global form load event

Posted on 2006-07-01
4
240 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now