An Overview of Project Templates
You can choose from several kinds of project templates when creating a new Visual Basic .NET project. This section introduces each
The Windows Application Project Template is the basic template for Windows applications. This project is created containing a single blank WinForm. Examples of Windows applications are provided throughout this book. Many are small applications demonstrating isolated topics. For more
The EmptyForm.sln described earlier in the chapter illustrates what the Studio IDE will provide for you when you begin a Windows Application project.
A class library project creates a DLL containing .NET classes. Class libraries in Visual Studio .NET are created similarly to COM libraries in Visual Basic 6 but aren't COM libraries. Rather, a class library in .NET is an assembly designed to work with the .NET Framework.
Set the project
Refer to the solution ClassLibraryDemo, which contains a trivial Windows application and a class library. The class library is defined in the namespace ClassLibraryDemo, which can be determined from the general view of the Common Properties in the Property Page dialog box. The TestClassLibraryDemo Windows application contains a reference to the class library. From there we can instantiate objects defined in the class library. (Refer to Chapter 7, "Creating Classes," for an example of a class library.)
Creating a Class Library
The basic steps for creating a class library begin with selecting the Class Library Project Template from the New Project dialog box. Implement classes in the class library as you would
Adding a Reference to and Using a Class Library
These are the steps you will need to take when using a class library:
Your application now has a reference to that class library. All these steps are very similar to the process in Visual Basic 6.
Having the reference to the library, you can create instances of classes in the library with the Dim statement and the fully qualified namespace and class
The imports statement is placed at the top of the source file. When you want to create a class from the ClassLibraryDemo, the following example works:
Dim MyVar As New LibraryClass()
Notice that the namespace isn't prefixed to the name of the class, LibraryClass. Also notice the parentheses at the end of the class, LibraryClass(). This is consistent with the constructor-calling convention used in other languages.
Alternatively, you can use the fully qualified namespace and class name to declare
Dim MyVar As New ClassLibraryDemo.LibraryClass()
There are some similarities in syntax for variable declaration and object creation, and there are some revisions that reflect changes in the underlying language.
If you want to create custom
Windows Control Library
The Control Library template contains a UserControl, an empty container control for creating visual components. UserControl is the original container control class carried over from Visual Basic 6.
ASP.NET Web Applications
Web applications allow you to create applications for the Web using WebForms, consistent with how you build applications for Windows.
Web applications are one of the keys to .NET. Use Web Application projects where you would have used the
Web applications take care of the complexities of defining the application server, the aspx files, and the HTML. When you are defining a Web application, the design-time environment is almost identical to the environment for Windows applications. This results in a much simpler and more consistent Web application development experience.
Web Application Development Preparation
To create, test, and debug Web applications, you will need to do a little preparation. You will need Internet Information Server (IIS) installed on your workstation or on your network. This is a prerequisite to installing VS .NET if you plan to build Web applications on that PC. You will also need to be in the Debug Users or Administrators
Creating a Demo Web Application
In Visual Studio .NET, choose File, Project, Web Application. The location for your application will be the URL of your Web server (IIS). Provide a name for the Web application, and click OK. By default you should get a blank application with one WebForm named WebForm1.aspx. The toolbox should have a Web Forms tab. These are controls imported from System.Web.UI.WebControls namespace.
Drag and drop a text box and button onto the WebForm (shown in Figure 1.7), and change the text property of the button to GoTo. (All of this works identically to making the same modifications on a WinForm.) Double-click the button. The IDE will generate an OnClick handler and open the WebForm1.aspx.vb source code in the editor. Add the code as shown in Listing 1.9 to redirect the user to the URL typed into the TextBox.Text property.
Figure 1.7. The design-time view of a Web application in Visual Studio .NET.
Listing 1.9 Using the Response class to redirect a Web application to another URL
1: Protected Sub Button1_Click(ByVal sender As System.Object, _ 2: ByVal e As System.EventArgs) Handles Button1.Click 3: 4: Response().Redirect(TextBox1().Text) 5: 6: End Sub
Press F5 to run the application. (Place a breakpoint on line 4 if you want to step into the code when the user presses the GoTo button.) When you press F5, the application will compile into a DLL and Internet Explorer will open with the WebForm. Enter a URL into the text box and click GoTo. You should be redirected to the Web site represented by the URL text.
What I hope you gather from this demo application is that Microsoft has made significant improvements to the process of developing Web-enabled applications. By writing VB code and presenting a design-time environment almost identical to that of standard Windows applications, programmers can leverage their VB programming skills when building Web applications.
ASP.NET Web Service
If Visual Basic .NET only brought us a whole object-oriented language and Web applications built with WebForms and ASP.NET, Visual Basic .NET would be a marvel indeed. But wait, there is much more.
There has been a general
Web services may or may not be intentionally designed as another step toward a microkernel, but Steve Balmer, CEO of Microsoft, was recently quoted as saying that client applications will probably be browser-based. Considering Balmer's position, this statement is more akin to goal setting than prognostication.
If the client is a browser and browsers are connected to the Internet and Internet server applications, we are already moving toward a time and place where computer resources may reside anywhere in the world.
This is what Web Services do for us. Web Services are a technology based on SOAP and XML technology. The basic idea behind a Web Service application is that the Web Service can reside anywhere and be used by any client application anywhere. Using a standard protocol like XML is a hedge to increase the
The Web Service Project Template creates an empty Web Service. Although VS .NET makes programming Web Services possible and easier, there is enough here that I will refer you to the chapters
Web Control Library
The Web Control Library Project Template is the basic project for building controls that can be used on WebForms with Web Applications.
The Empty Project Template creates a solution with a single Windows Application project containing no forms, modules, or references.
Empty Web Project
The Empty Web Project Template creates an empty Web solution and project.
New Project in Existing Folder
The New Project in Existing Folder Template creates a blank Windows Application project without creating a new folder, named after the project.
Enterprise Edition Projects
There are several project template types available only in the Enterprise Edition of VS .NET. Each is covered briefly in the subsections that follow.
Create a Database Project by choosing File, New, Project, Other Projects, Database Project. The database project stores references to the database and allows you to run scripts and queries.
The Database Project allows you to manage and create queries, triggers, stored procedures, modify the database, database references, and contains a visual query designer. If you have used Access, the views in the Database project will look superficially familiar.
Visual Basic Simple Distributed Application
The Visual Basic Simple Distributed Application template creates a Windows Application project that includes empty classes for all the various aspects of distributed applications that you might include.
The basic template includes a WebForm, a WinForm, a class for managing database access, another class for managing business rules, and a few other empty classes.
You can use all these features in a distributed application, but more than likely you will use one presentation layer, perhaps a business layer, and a persistence layer. Thus you more than likely will use either WebForms or WinForms but probably not both.
We won't cover a project
Visual Basic Distributed Application
The Visual Basic Distributed Application template creates a blank project
The kinds of projects added to the project template are defined by a policy file. The purpose of the policy file is to describe the application types and components that describe the technology that will be used for a given application type and act as a technology guide.
The Analyzer Project creates a solution for managing a Visual Analyzer session and resultant profiling data. Effectively using the Visual Analyzer and profiling is an important subject but beyond the scope of this book.
Visual Studio .NET Add-In
You can select from the Visual Studio .NET Add-In or Shared Add-In. These project templates are defined under the Extensibility Projects subfolder in the New Projects dialog box.
Visual Studio .NET has added macros and an Automation Extensibility Model for customizing and extending Visual Studio itself. One of the characteristics of a first-class tool is that the tool can be used to extend itself. Visual Studio fits that bill.
Refer to Chapter 4, "Macros and Visual Studio Extensibility," for more information on add-ins.
The Shared Add-In project allows you to select from a wide variety of application
Shared Add-Ins can be used in any of the hosts you select during the wizard creation phase.