Commonly Used .NET Classes

   

Literally hundreds of classes make up the .NET Framework, many of which are support classes for the more widely used classes. However, a few classes stand out in the .NET Framework as ones often used in building .NET applications. Again, refer to the online help shipped with Visual Studio .NET for a complete reference to these and all the classes in the .NET Framework.

The System::Windows::Forms::Application Class

The Application class provides methods and properties to manage an application. It is analogous to the CWinApp class in MFC because it has methods to start and stop an application, process Windows messages, and properties to get information about the application.

Unlike with the CWinApp class, you do not derive a class for your application from the Application class. Instead, all the members, methods, and properties are static and therefore callable without a created instance.

A common use of the Application class is running an application by providing the message loop for a Windows Form. You can also exit the application or current thread with the Application class's methods.

If your application requires processing of Windows messages, you can also use the Application class to add message filters to the application's message pump.

The System::Windows::Forms::Form Class

The Form class provides the foundation for displaying any window within your application. It is capable of creating a standard, borderless, floating window. The Form class also supports creating a multiple-document interface (MDI) frame and child windows. The Form class is similar to the CWnd class in MFC in that it is the basis of all windows; however, the Form class is not the base class for controls.

Using the properties of the Form class, an application can determine the appearance, size, color, and other features of the window or dialog. In addition to the properties, methods are provided to manipulate a form.

In order to create a new window, you must derive a class from the Form class and provide an implementation that sets the properties, adds any required controls, and handles the events for the window. The Form class is not designed to be used directly.

The System::Threading::Thread Class

Creating and running threads within the .NET Framework is managed through the Thread class. This class has all the methods necessary to manage a thread, similar to the MFC equivalent CWinThread class.

The .NET Thread class is more complete than the MFC CWinThread class in that it also includes methods for working with thread data, or thread local storage (TLS), and thread execution.

The System::IO::File and System::IO::FileInfo Classes

The File class is another class where all methods are static and can therefore be called without having an instance of the class. Because the File class performs security checks on all methods each time you use one of these methods, it can cause performance issues when heavily used. You can solve this by using the related FileInfo class, which provides methods and requires that you instantiate it in order to work. Because an instance of the FileInfo class is used, the security checks are only performed once.

The FileInfo class is similar to the CFile class in the MFC library because they both provide file I/O support and require an instance of the class to work. The File class in the .NET Framework is very useful for quick-and-easy file operations that don't occur often or within processes.

The System::Drawing::Graphics Class

The Graphics class encapsulates Microsoft's new graphics APIs, known as GDI+. Drawing graphics within an application is a much easier task with GDI+ and the Graphics class because you no longer work with Device Context (DC) handles and the issues involved with them.

GDI+, and hence the Graphics class, also provides a more robust API with advanced capabilities for gradient shading and other graphic effects that were difficult to perform before GDI+. There isn't a corresponding class within the MFC library because GDI+ has its own class library that is mirrored with the Graphics class in the .NET Framework.

The System::Web::Services::WebService Class

Classes implement a Web Service by deriving from the WebService class, which gives them access to the ASP.NET objects. These objects include Application, Session, User, and Context, which are useful when you're writing Web Services.

Creating managed Web Services is one of the primary uses Microsoft envisions for the Visual C++ .NET compiler. Therefore, Microsoft has made Web Services simple to write, and the WebService class is an integral part of that development.

The System::Data Classes

Storage and retrieval of data is important in today's connected world. The System::Data classes form what is known as ADO.NET, the obvious progression of the familiar ADO technology into the .NET environment. However, with the addition of Web Services, Microsoft has updated the technology to allow for data transfers using a common file format (XML) and Internet protocol (HTTP).

The major class within the System::Data namespace is the DataSet class. Using DataSet as the starting point, one or more DataTable objects are created within that set. Furthermore, the DataSet object can also contain data constraints using the Constraints class and data relationships using the DataRelations classes.

The tables mentioned earlier can be created with something known as a data adapter. Currently, two data adapters are installed with Visual Studio .NET: the OLE DB data adapter (OleDbDataAdapter), provided by the OLD DB .NET Data Provider, and the SQL data adapter (SqlDataAdapter), provided by the SQL Server .NET Data Provider.

The System::Xml Classes

If you've spent even just a small amount of time reading through .NET documentation, you've probably noticed the prevalence that XML has within various portions of the framework. In fact, XML is at the heart of Web Services because it is the data format used to transport information over networks.

In previous versions of Visual C++, if you planned on incorporating XML into your applications, a separate download was required to get the necessary header files and libraries. With Visual Studio .NET, everything you need is already built in. The XmlReader class provides the necessary logic to support the reading in of XML files. One difference between this class and previous downloadable versions of MSXML (the Microsoft version of an XML parser) is that it doesn't use the same design paradigms. In other words, rather than being solely a DOM parser or solely a SAX parser, it is a combination of both. Although you are able to select and manipulate nodes similar to a DOM parser (also known as the pull model of parsing), it is a forward-only reader similar to the SAX parser.

The System::XML classes also contain an XmlWriter class designed to easily write XML data. Like the XmlReader class, XmlWriter also implements a forward-only method for XML data. XmlWriter outputs data that conforms to the W3C Extensible Markup Language 1.0 Second Edition recommendation.

The System::Web::UI::Page Class

Although Web Forms are created in an ASPX file that resides on the IIS server, the logic behind the Web Form is provided by the Page class. Writing the logic for a Web Form involves writing a DLL file that is used with the ASPX file. The DLL provides a class derived from the Page class that implements the logic of the ASP.NET Web Form.

When the user first visits a Web Form, the ASPX file is compiled with the DLL file and, in essence, becomes a compiled program that produces HTML output for the user to view.

The Page class is the Web equivalent of the Form class for Windows Forms. It provides all the information and support needed to program a robust Web user interface with Web Forms.

The System::ValueType Class

All structures and enumerations in the .NET Framework are implicitly derived from the ValueType class. All structures and enumerations that you define within your application are also implicitly derived from the ValueType class. The derivation is enforced by the compiler and is not explicitly defined within the declaration. For example, when you declare a structure or an enumeration, the compiler automatically derives those types from the ValueType class.

Deriving from the ValueType class provides a common set of functionality for all value types within the .NET Framework. The Equals, GetType, and ToString members are the primary functionality provided by the ValueType class besides giving all value types within the .NET Framework a common base.


   
Top


Sams Teach Yourself Visual C++. NET in 24 Hours
Sams Teach Yourself Visual C++.NET in 24 Hours
ISBN: 0672323230
EAN: 2147483647
Year: 2002
Pages: 237

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