Solved

Global form load event

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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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