Section 6.2. Referencing Components and Classes


6.2. Referencing Components and Classes

Applications you develop in Visual Basic will contain custom classes and other .NET types, defined for the specific needs of the application. But you probably want to take advantage of other code already written, such as the classes in the .NET Framework Class Library. Namespaces and classes that you do not write yourself must be specifically identified before they can be used in your code. This is done in two steps.

  1. Reference the assembly that contains the classes you wish to use. This is done through the References section of the Project Properties for your application. For instance, to use the Windows Forms features of .NET, your application must include a reference to the System.Windows.Forms.dll file, which contains the System.Windows.Forms assembly and namespace contents. When you create new projects of a specific type (such as a new "Windows Application" project), the typical assemblies you need for that project type are referenced by default.

  2. Specify the class or feature you want to use with its namespace. For instance, to use the Form class, you must call it System.Windows.Forms.Form. Typing this much text quickly becomes a burden, so .NET allows you provide relative names through the use of the Imports statement. For example, the statement:

         Imports System.Windows.Forms 

    in a code file allows you to use the Form class without its full qualification. You can set up global Imports-like settings through the Project Properties. Visual Studio defines several global Imports-like settings for you based on project type.




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