Case for a simple approach
Sometimes it is very useful for a class or even UserControl (which is really just a special class) to have properties and methods for widespread use throughout the program.
If the main problem is the widespread use of “utility” methods, which are stateless (for example, concomitant web communications that have URL encoding methods, object encodings, etc.), this can be pretty cheap just to have an additional global instance declared "without" events that you are not raising to load a heavy internal state (arrays, collections, etc.). Since your program still needs code, and only one copy is in memory, the second instance can be quite cheap.
Another option is to separate these “general” operations and even property values into a separate class or static (BAS) module.
But sometimes you have a rather complicated UserControl or class that you do not want to configure by refactoring into separate modules or otherwise changing. Perhaps you support common standard versions for use in different projects. Perhaps this is a third-party library in which you do not even have a source. Whatever.
To consider something
This leads us to another method that may work for you, although in the immortal words of Irving Mainway it is "not for blind children." If you are experienced enough to use this, then this should already have happened to you, but none of us has the perfect memory (if we really ever found the time to read this wonderful guide).
So maybe this will not work for you for some reason, and you have already considered and discarded this idea.
The object of your container (Form, UserControl, parent class, etc.) can carefully establish a global link to an instance of the object in question when it initializes and deletes the link when it is completed. This should be done with some caution in order to avoid circular or orphan links, which may interfere with the unloading of other objects or even your entire program.
This should not be probable or carelessly used by Johnny GoTo. But if you know what you are doing in VB, and you actually read and understood the parts of the manual that discuss this technique and its pitfalls, this can be useful.
Suppose you have Form1 as the object to run the program. In Form1, you have an instance of the UserControl "WebWiz" that you wrote, named WebWiz1. But in another place (three or twelve more forms?) You want to call the WebWiz method, which converts a set of standard values of the MIME type to file extensions. Only Form1 needs to handle WebWiz1 events, and WebWiz is pretty heavy for internal state, so you do not want to create additional instances for this method only.
In a static module, you can simply declare:
Public gWebWiz As WebWiz
When you run Form1 Initialize or Load events (or for a class after creating an instance of WithEvents ), you can:
Set gWebWiz = WebWiz1
In the 1st form event handler:
Set gWebWiz = Nothing
Then your program has a global link that it can use for different purposes.
Looks easy?
Well, if your programs using this are written as the correct "tree" of code, starting with Sub Main or the main form, you usually do not need to be very careful. But if you are one of those people who wrote like “Pinball Master” and are wondering, “How do I find all my open forms and unload them?” then you:
- You have more work to avoid programs that freeze and
- This is probably actually not the case.