Form Handling

doingITBeta

Member
Joined
Jan 9, 2012
Messages
5
Programming Experience
10+
I noticed that there is a lot of contradictory information on the Net about how to do basic things like show forms. It appears to me that in the initial phases of VB.Net, it wasn't possible to use code like this:

Form2.Show

In 2002, Microsoft said that this command would raise an error because VB.Net did not create its own default global form instances (unlike VB6). This is covered is more detail at Working with Multiple Forms in Visual Basic .NET: Upgrading to .NET and Opening, Closing, and Hiding Forms with Visual Basic .NET - For Dummies

However, by 2009, VB.NET was creating it's own default form instances and the above code became valid. This is covered in more detail at John McIlhinney's .NET Developer Blog: VB.NET Default Form Instances

If someone could fill me in on precisely when in .Nets evolution this change was made, it would be appreciated.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,335
Location
Sydney, Australia
Programming Experience
10+
Quite a lot of things changed with the move from .NET 1.1/VB.NET 2003 to .NET 2.0/VB 2005, including that. I don't know what the exact thinking was a MS but the consensus is that default instances were added to appease many VB6 developers migrating to VB.NET because that's the way forms work in VB6. In theory, default instances do make it easier for beginners because they don't have to think about how to move data from one form to another. In practice, it has caused a lot of confusion too because many developers get mixed up when they mix the two. If you understand how objects work then there's never a need to use default instances. Using explicit instances takes very little extra code and anything that is made easier by using default instances is something that a good developer shouldn't be doing anyway.
 
Top Bottom