Contrary to popular belief, the generation of Default Instances in a WinForm application is not a mandatory feature of Visual Basic.
From the Visual Basic Language Specification Version 11 (emphasis added) :
11.6.2 Default Instances In some situations, classes derived from a common base class usually or always have only a single instance. For
example, most windows shown in a user interface only ever have one
instance showing on the screen at any time. To simplify working with
these types of classes, Visual Basic can automatically generate
default instances of the classes that provide a single, easily
referenced instance for each class.
The problem is that I know of no documentation that tells you how to enable/disable their creation. It is known that this feature is part of the Application Framework that can be enabled/disabled in the "Application Tab" of the project's properties pages. However, disabling the Application Framework does not disable the default instance generation.
If instead selecting the "Windows Forms App" template when creating a project, you select the "Empty Project" template and proceed to add a form, you can create a WinForm project in which the "Enable application framework" checkbox is grayed out and not selectable. You will also find that you can not use default form instances. From this, you can deduce that this feature can be configured via "*.vbproj" file.
The controlling item is the <MyType>
tag. The possible values for this property are:
- Empty - application framework unavailable
- Console
- WindowsForms - application framework enabled
- WindowsFormsWithCustomSubMain - application framework disabled
- Windows - Class Library
- WebControl - library
So if you want to convert an existing project to one that does not support default instances, you can edit the "*.vbproj" file and change the <MyType>
property to Empty.
Be aware that doing this will also eliminate other features of the application framework such as My.Computer
and My.User
, but you could always implement those features yourself such is described in How to: Use the My Namespace (C# Programming Guide).