Thoughts on Visual Basic 2005 form Exchange Technology

Source: Internet
Author: User
Every day, programmers of VB6 start to transfer to. NET for development. The primary problem they face is getting used to the object-oriented Golden laws in. NET. Therefore, the forum will repeatedly hear netizens discuss how to access forms in Visual Basic. NET 2003. Earlier, I published an article on the solution to this problem. By rewriting Sub New, I used the Me keyword to get an instance of another form in the New form. Now the VB2005 era is coming soon. Will there be a simpler way? The answer is yes. All mysteries are hidden in the My. Forms namespace!
In fact, there is nothing worth doing here. To maintain the default instance of any form class, this function was provided in earlier versions of VB. In. NET 2003, VB reluctantly cut this feature out in pursuit of consistency with other object-oriented language styles. While VB2005 is innovating, Microsoft seems to look at the features deleted in VB6 from a more rational perspective (existence is rational, isn't it ?), Maintaining the default form class is a technique that is retrieved again. However, the default instances of all forms are now unified in My. under the Forms namespace (for example, My. forms. form2), changed the chaotic governance style in VB6 (Oops, wow, wow ). However, when writing code, you can still omit My. Forms. For example, you can write in Form2.vb as follows:
Private Sub button#click (ByVal sender As System. Object, ByVal e As System. EventArgs )_
Handles Button1.Click
Form1.Text = "Hello My. Forms"
End Sub
Haha, have you found the feeling of VB6 again?
As a matter of fact, when I first came into contact with this feature in 2005, I was quite uncomfortable. As I used to develop in 2003, I always went to a New form myself. So I was wondering, if every time the program is started, is My. Forms automatically generating a default form instance for us? If we don't use this instance, isn't it a waste of memory? In fact, this is not the case. I think it is necessary to say the following here.
When Visual Basic executes your code. in Forms, when an instance is referenced, say, Form2, the first thing it does is to first determine the default instance of the Form2 form (note, is the default instance instead of the New instance) whether it has been created. If yes, the instance is referenced. If no, a default instance is created. That is to say, if My. Forms. Form2 does not appear in your code, the default Form2 instance will not be created at all! Therefore, the My. Forms namespace only automatically maintains the default instance of the form, rather than automatically creating the form. Similarly, My. Forms is generally not responsible for automatic recovery of default instances.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.