The topics in this part are listed below. The code snippets if any are based on the new C++ .NET syntaxes. The code snippets if any are based on the new C++ .NET syntaxes.
The Drawing Namespaces
A number of namespaces provide all the graphics functionality for the .NET Framework:
The original set of Windows graphics routines was called GDI, for Graphical Device Interface. It provided a very simple set of two-dimensional graphics primitives, so you could draw lines, circles, rectangles, and other simple shapes, as well as strings of text. The .NET Framework has built on this functionality, and its graphics library is called GDI+.
The Forms Namespace
Visual Basic programmers have been used to programming with forms for some time. GUI applications in Visual Basic consist of a number of forms, each of which is a separate top-level window. Developers select controls, such as buttons and list boxes, from the toolbox and drop them onto the form. Every control has properties and methods associated with it; the Visual Basic Property Editor allows interactive modification of properties at design time, and both methods and properties can be accessed from code at run time. The System::Windows::Forms namespace provides Visual Basic-style form-based development to all .NET languages, including C++. This namespace is huge, containing over 300 classes, structures, and enumerations. There will be more namespaces when the .Net Framework version is updated. The following table lists some of the most important classes to give you a feel for what is available.
|
Class | Description |
Application | Provides methods and properties for managing applications. |
AxHost | Wraps Microsoft ActiveX controls so that they can be used as Windows Forms controls. |
Button | Represents a Windows button control. |
CheckBox | Represents a Windows check box control. |
CheckedListBox | Represents a list box control that has a check box to the left of each item. |
Clipboard | Gives access to the system clipboard. |
ColorDialog | Displays a standard color picker dialog box. |
ComboBox | Represents a Windows combo box control. |
Control | The base class for all controls. |
Cursor | Represents a cursor. |
DataGrid | Displays Microsoft ADO.NET data in a scrollable grid. |
DateTimePicker | Represents a Windows date-time picker control. |
DomainUpDown | Represents a Windows up-down control that displays string values. |
FileDialog | The base class to display the standard File Open or File Save dialog boxes. |
Form | Represents a window or a dialog box that makes up part of an application’s user interface. |
Label | Represents a Windows label control. |
ListBox | Represents a Windows list box control. |
ListView | Displays a list of items in one of four views. |
Panel | Represents a Windows panel control. |
RichTextBox | Represents a Windows rich text box control. |
StatusBar | Represents a Windows status bar control. |
TextBox | Represents a Windows text box control. |
ToolBar | Represents a Windows tool bar control. |
Table 12 |
The Net Namespaces
Networking support is provided by the System::Net and System::Net::Sockets classes. System::Net provides an interface to many of the protocols commonly used today, such as manipulating IP addresses, making DNS lookups, talking to HTTP and FTP servers, managing cookies, and authentication. System::Net::Sockets provides an implementation of the Berkeley Sockets protocol and provides a .NET wrapper around the Windows WinSock API.
The Xml Namespaces
XML is heavily used throughout the .NET Framework, and several namespaces provide support for creating and manipulating XML:
System::Xml, which provides the basic classes needed for processing XML.
System::Xml::Schema, which provides support for XML Schemas.
System::Xml::Serialization, which lets you serialize .NET objects to and from XML.
System::Xml::XPath, which contains the XPath parser and evaluation engine.
System::Xml::Xsl, which contains the Extensible Stylesheet Language (XSL) processor.
Using these classes, it’s possible to perform all the manipulation of XML that you’ll ever need to do. These classes make the .NET Framework one of the most productive environments for XML programming.
The Data Namespaces
The System::Data namespaces hold the classes that implement ADO.NET, a new version of Microsoft Active Data Objects technology optimized to work with the .NET Framework, which enables you to build components that manage data from a number of data sources. Data from different data sources is provided by data providers, of which there are three shipped with the .NET Framework. The .NET Framework Data Provider for OLE DB uses Microsoft COM-based technology that makes it possible to use many different kinds of data sources, such as relational database tables, Microsoft Excel spreadsheets, and even text files, as if they were databases. The .NET Framework Data Provider for SQL Server works with data from Microsoft SQL Server. Finally, the .NET Framework Data Provider for Oracle makes it possible to work with Oracle databases from .NET code. The most important class in the System::Data namespaces is DataSet, which represents an in-memory cache of data retrieved from a data source. A DataSet consists of one or more DataTable objects, and these in turn consist of a collection of DataColumn objects.
The Web Namespaces
Because one of the main reasons for introducing the .NET Framework was to make it easier to build Web applications, it’s perhaps no surprise that the .NET Framework contains a number of namespaces related to Web programming. These are all related to Microsoft ASP.NET, the latest version of Microsoft Active Server Pages technology that is optimized to work in the .NET environment. The most significant of the Web namespaces are listed here:
System::Web, which provides the basic functionality for browser-to- server communication over HTTP, including the HttpRequest and HttpResponse classes that enable an ASP.NET page to exchange data with the client using HTTP.
System::Web::Mail, which lets you prepare and send e-mail attachments using the SMTP service built into Windows 2000, Windows XP, and Windows NT.
System::Web::Security, which provides classes that implement security in ASP.NET.
System::Web::Services, which provides the classes that let you build Web services.
System::Web::UI, which contains all the classes that let you build server-side controls.
The features provided by two of these namespaces merit particular mention. Web services, in particular, are a great new feature introduced by the .NET Framework. A Web service is a programmable entity living on a Web server that can be accessed using standard Internet protocols. What this means in practice is that you can expose a function on a Web server that others can call.
Communication between client and server uses standard protocols, such as HTTP, and data is usually passed to and from the Web service in XML format using SOAP. The use of XML over HTTP makes it possible to access Web services easily from clients written in just about any programming language on any platform. It’s also possible to find out what services a Web server supports, and it’s very easy in Visual Studio .NET to write clients that make use of Web services. The System::Web::UI namespaces let you build server-side controls. You program these as if they were normal controls, but their code executes on the server. The System::Web::UI::HtmlControls namespace contains classes that represent HTML server controls that map directly onto standard HTML elements, such as buttons and forms. System::Web::UI::WebControls is more abstract and lets you program server-side controls that might not map directly onto HTML.
.NET Compact Framework
The .Net compact framework is a hardware-independent environment for running programs on resource-constrained computing devices. It inherits the full .NET Framework architecture of the common language runtime, supports a subset of the .NET Framework class library, and contains classes designed exclusively for the .NET Compact Framework. Supported devices include personal data assistants (PDAs) (such as the Pocket PC), mobile phones, set-top boxes, automotive computing devices, and custom-designed embedded devices built with the Microsoft Windows CE.NET operating system.
A summary for this module
To | Do this |
Use data structures such as dynamic arrays, lists, and hash tables. | Use the classes in the System::Windows::Collections and System::Windows::Collections::Specialized namespaces. |
Create a form-based application. | Use the classes in System::Windows::Forms, and derive a class from System::Windows::Forms::Form. |
Work with XML. | Look at the classes in the System::Xml namespace. |
Trace program execution, interact with the event log, or monitor system performance. | Use the classes in the System::Diagnostics namespace. |
Work with databases using ADO.NET. | Look at the System::Data namespaces. |
Table 13 |