Section F.2. The My Namespace


F.2. The 'My' Namespace

One of the biggest features included with Visual Basic 2005 is the new My Namespace feature. This feature adds a new namespace named My at the top of the namespace hierarchy, parallel with the System namespace. This namespace contains a conveniently arranged subset of the features available in the Framework Class Library, designed to be as easy as possible to use. The My namespace is a hierarchy and contains different branches covering major subsets of functionality. For instance, the My.Computer.Network portion of the hierarchy provides access to properties and methods that relate to the local computer's network.

Most of the My namespace is static, with specific features permanently located at known locations. However, parts of the hierarchy are dynamic, with different items included depending on the configuration of the system and the application. One of these dynamic sections, My.Forms, makes available all of the forms in the current application. This collection changes dynamically as forms are added to the application, either at design time or at runtime.

One use of the My.Forms dynamic collection is the ability to reference a form directly and display it on-screen without first creating an instance of the form. The general syntax to display a form in this manner is:

    My.Forms.Form1.Show() 

The same statement also appears in a simplified form:

    Form1.Show() 

which is quite similar to the syntax used in VB 6. These default instances simplify the accessibility of forms.

Another new 2005 feature works hand in hand with some of the My Namespace feature elements. Portions of the namespace expose application-wide events, events that impact the entire application and not simply one control or class. To support these events, Visual Basic includes a new "application framework," a set of features that simplify the management of an application's lifetime, from startup to shutdown.

All of the My Namespace features are documented in Chapter 13. A hierarchical listing of the elements included in the My Namespace hierarchy appears in Appendix B.




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net