Global FormClosing/Load events in .NET

54 Views Asked by At

I'm using VB.NET 4.7.2

I have a multi-form application and I'm coding the "Window" menu on top to show open forms so the user can easily switch (now that Win11 has forced combining applications on the taskbar).

I need each open form to be able to handle the FormOpening and Load events generated by other forms. My current solution is to handle those events locally in each form, which then triggers a custom global event that any other form can handle.

But that's a little tedious - is it possible for one form to handle another form's closing or opening without this workaround?

1

There are 1 best solutions below

0
Steve Todd On

You could subclass a standard form to do all the scut work of registering with the shared global and hooking other forms events. You then just need to change the forms header to point at the subclasses type and off you go.