Global FormClosing/Load events in .NET - vb.net

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?

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.

Related

undo for non textbox controls

new to .net coming from vba decided to rewrite a management app using vb.net and SQL Server.
Started writing the base library for my application.
I created custom controls to use in my application that would expose a Zoom function, background color for the current active control a .modified property similar to the one available in textbox and some extra other properties (SQLTableName, SQLColumnName, ...) to enable iterating through a container (form) for modified controls and Update/Insert into a SQL table via a SQLProcessClass.
Concurrently I'd like to also implement a simple undo functionality.
My first idea was to add a PrevValue variable set in the OnEnter event if the Modified property is False, exposing an OldValue property and an Undo method in the custom controls.
However I found that the TextBoxBaseClass already exposes an Undo method and that there is an UndoEngineClass available.
Unfortunately the vs helpfile does not give examples of how to use / implement that class.
Could someone explain the usage of the UndoEngine class non-textbox controls and if it is advisable to use it or rather write my own (as I first intended to do - I also found some interesting articles about undo/redo classes) but why reinvent the wheel in case .net already provides a class for it.
thks

Is there any intelligent way of handling VS event handler removal after copy/past of control

I am using VB.Net 2008 and have been experiencing event handler removal after I do copy/paste of controls, such as to group box or panels. I had to add event handles manually for every control. When I try to move them instead of copy/paste, I had to deal with the z-order of each control. That is also a manual work. And this all becomes time consuming when there are several of them.
My questions are:
1) Is this a problem only for VS 2008 or for all VS?
2) Is there any other intelligent way of handling this issue?
Unfortunately, that's the way it is up through VS2013 at least.
If this is a recurring problem with a certain set of controls, you can create a user control containing them and put most of the offending handlers inside the user control.

I want to make a control builder program when I add my custom control to the winform - VB.NET, VS2008

I am currently building custom user controls and would like to have a program (that I write) that sets the properties for the control when it is dragged onto the form.
I've seen this working with some controls I've been using - an external program opens (or is available by right clicking on the control).
How is this accomplished?
Edit: An example of an application I use that does this is Farpoint Spread Designer; You can right click on the component and launch the designer application.

SharePoint 2010: trying to understand life-cycle issues with visual web part

I am building a visual web part which has a number of user-configurable properties. The web part will display news items and, optionally, automatically switch to the next item after a defined pause.
The problem I'm having is that the user control part has a timer which fires events. These events reenter the user control (without going through the web part) and I see that when this happens the user control is in an unitialised state - i.e. the custom properties of the web part have not been applied. This causes the control to behave in it's default manner.
What am I doing wrong?
When you set property in your webPart, you need to bubble it down to the User control.
See creating custom properties for visual webparts:
http://patricklamber.blogspot.com/2010/05/how-do-i-create-custom-properties-in.html

vb.net - problem making a call from one usercontrol to another form

I have a tabcontrol that creates tab pages from a "User Control" I created (a separate form in vb.net) using this code: (MainTab is the separate user control I created which has text boxes etc in it)
Dim tmpTab As New MainTab
myTabControl.TabPages.Add()
Dim tmpTabCount As Integer = myTabControl.TabPages.Count
myTabControl.TabPages.Item(tmpTabCount - 1).Controls.Add(tmpTab)
myTabControl.TabPages.Item(tmpTabCount - 1).Text = "Untitled"
I'm using the devexpress xtratab control so the code might look a bit different than the default vb.net tab control.
Now in my MainTab user control file file, I can't for the life of me figure out how to call a control in the form1 where the xtra tab control is placed on. "Me.Parent.Dispose" works for closing the tab when executed via the MainTab control, but that's as far as I can get for communicating with the parent from.
Does anyone know the solution? I'm not sure if I have to reference something in the MainTab user control or what in order to communicate with any objects on the default form1.
Generally speaking, I avoid making my child controls cognizant of the parent. It leads to unpleasant coupling more often than I care for.
Consider adding a custom event to your MainTab class that your form can subscribe to. When you want to pass a message to the form, your user control can invoke the method, and your form's event handler can process it accordingly. This pattern helps keep your user control pluggable into other forms by reducing its dependency on its parent.
Creating a user control event in a windows form is discussed in this MSDN article:
http://msdn.microsoft.com/en-us/library/aa302342.aspx