Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Microsoft C# Professional Projects - Premier Press.pdf
Скачиваний:
177
Добавлен:
24.05.2014
Размер:
14.65 Mб
Скачать

WINDOWS FORMS AND CONTROLS

Chapter 8

 

143

 

 

 

 

 

FIGURE 8-1 The Solution Explorer window

A project includes an HTML file, a project file, and source files. In addition, you may include several other files in your project, depending on the complexity of the application you create. For example, you may create an .xsd file to include a dataset in your project. You will learn about these files later in this project.

When a project is completed, you usually convert the project into an executable program (.exe), a dynamic-link library (.dll), or a module. The following sectio n discusses how to create a new project.

Creating a New Project

To create a new project in Visual Studio .NET, perform the following steps:

1.On the Start menu, point to Programs and click on Microsoft Visual Studio .NET.

2.From the list that is displayed, select the Microsoft Visual Studio .NET option.

The Microsoft Development Environment window is displayed.

144 Project 1 CREATING A CUSTOMER MAINTENANCE PROJECT

FIGURE 8-2 The Project option of the Add New dialog box

WINDOWS FORMS AND CONTROLS

Chapter 8

 

145

 

 

 

 

 

FIGURE 8-3 Templates provided by Visual Studio .NET

Using the available templates, you can create a variety of applications, such as Windows applications, ASP.NET Web applications, ASP.NET Web services, console applications, and so on. In this chapter, you will learn about console applications and Windows applications. However, ASP.NET Web applications and ASP.NET Web services will be discussed in the next project.

Console Application

Using Visual Studio .NET templates, you can create applications that display the output in a console window. Such applications are called console applications . To create a console application, select the Console Application project template in the right pane of the New Project dialog box. In the Name text box, specify the name SampleConsoleApplication.

When you create a console application, Visual Studio .NET adds the necessary files to the project.These files include References, App.ico, and AssemblyInfo.cs. You will learn about these files later in this chapter.

In addition to the previously mentioned files, a class file with the name Class1.cs is created. This file contains empty code for the class module. Figure 8-4 shows

the Class1.cs file.

146 Project 1 CREATING A CUSTOMER MAINTENANCE PROJECT

FIGURE 8-4 Class1.cs file

A console application does not have a user interface, and it is run from the command prompt. You can now create a simple console application that displays the

message This is a sample console application. in the console window.

To display the message, you need to add the following code to the void Main() method of the application.

static void Main(string[] args)

{

Console.WriteLine(“This is a sample console application.”);

}

The WriteLine() method is present in the Console class, which lies in the System namespace.The WriteLine() method is used to write the current line to the Console window. Similarly, to read from the Console window, you can include the Console.ReadLine() method in the following manner:

static void Main(string[] args)

{

Console.WriteLine(“This is a sample console application.”);

Console.ReadLine();

}

The output of the previous code is displayed in Figure 8-5.