Skip Navigation LinksHome > Categories > Code from a Category

VB.Net 2008 Handle Multiple Forms



User Name: jamest85
Name: James T
Contact Me: www.datawebcoder.com/ContactUs.aspx
Home Page: www.datawebcoder.com
4 years experience on Zoho consulting, implementation, and programming using C#, VB, Php..., 9 years of total IT experience including programming and application development. 5 years of Experienced an... [More]
Viewed Times: 393
Add Date: 08/30/2010
This post shows how to handle multiple forms in vb.net.
From this post link: http://devcity.net/articles/94/1/.aspx, you can find there are 7 ways to tracking and interaction other forms:

However, I am still not conformable those ways to handle the forms. I am reading this book: Pro .NET 2.0 Windows Forms and Custom Controls in VB 2005, and I find below is the way which is pretty suitable for most of my applications:

Visual Basic includes a shortcut that allows you to communicate between forms, Each form has a default instance, a form object that's created automatically when needed. The best way to use the default instance is through the My.Forms object, which is hard-wired into the VB language. For example, if you have the form classes Form1, Form2, and Form3, you can access their default instances through the My.Forms.Form1, My.Forms.Form2, and My.Forms.Form3 properties: This code accesses the default instance of From1 and calls the Show() method. Here's the interesting bit: VB uses a lazy creation technique to generate default instances. That means that the default instance is instantiated when you refer to it for the first time. As a result, the line of code shown above may or may not create Form1. If the default instance of Form1 hasn't been created yet, it will be instantiated automatically. On the other hand, if the default instance has already been created, no instantiation is required. Also, if two different forms use above code, it won't create two same Form1s, only one instance.

Above code is create a form object implicit rather than explicit. To create explicitly, we need do this: Don't mix implicit and explicit in your code, otherwise, will create two objects for the same Form1 class, and ends up one form is updated, and another form remains out of reach.

Post a Comment

Name: (Optional)
Email: (Optional, you can get an email if somebody replys your comments)*
Email me if somebody respons my comment below:
Details**:
Enter Text
as Below:
(case insensitive, if hard to read, click the "get a new one" button)
 
    
* Your email address will not be shared with any third parties for any reason.
** Maximum 1000 charactors.