Trang

Chủ Nhật, 19 tháng 5, 2013

Chapter 2: Visual Studio .NET



Many people always get confused with Visual Studio .NET (VS.NET) and .NET technology. VS.NET is just an editor, provided by Microsoft to help developers write .NET programs easily . VS.NET editor automatically generates lot of code, allows developers to drag and drop controls to a form, provide short cuts to compile and build the application etc.



Understand Visual Studio .NET

VisualStudio is a very user friendly tool. But there are enough stuff to confuse any one new to Visual Studio family. The purpose of this chapter is to make you familiar with different options in Visual Studio.NET (VS.NET) We will not cover the entire visual studio guide. We are just explaining the most commonly used features of VS.NET.

When you work on any project, VS.NET has several child windows to assist you in the application development. These windows are attached on the left, bottom and right sides of the main window. You can click on these small windows to expand it and see the content of them. Some of the most commonly used child windows are explained below. Most of these windows will be enabled only when you have created a project and working on a WebForm/WinForm.
Toolbox
Toolbox provides all the drag and drop controls for your application. Depending on the kind of application you are working on, the toolbox will show appropriate controls and you can drag and drop them to your form. If you are developing a web application, toolbox will show ASP.NET controls and if you are developing a Windows application, it will show Windows controls (like Radio button, text box, buttons etc).

You can simply drag and drop any controls from the toolbox to your form. After you drag and drop any control, double click on the control to go the default event associated with the control.

The Toolbox will be enabled only when you have a WebForm or WinForm opened in Design mode and is usually located on TOP LEFT corner of the VS.NET.

By default, all windows including Toolbox will be displayed as Minimized (Marked as A in picture). You will see only the small icon and the text 'Toolbox' written vertically on the left bar of VS.NET. You can click on this minimized window to expand it (Expanded window is marked as C.). When you move the mouse away from the window, it will again automatically minimize. You can keep the toolbox always expanded by pressing the pushpin (Marked with B.)

The above behaviour is common for all the windows explained below. They will be minimized by default and you can point the mouse over it to expand it. Use the pushbutton to keep it expanded.

Picture 1 : Toolbox

Picture 2 : Design/HTML mode
Design mode & HTML mode

If you are developing a web application, you can switch between design mode and HTML mode for any web form. When you are in HTML mode, it will show you the HTML tags and ASP.NET code and you can manually edit it. YOu can switch to the Design mode by clicking the Design button on BOTTOM LEFT corner of VS.NET. In design mode, you can see how your ASP.NET page is going to look like when some one view your web page. Also, you can drag and drop controls from the toolbox, which will automatically generate the HTML for it.

Typically, developers switch between these two modes very frequently. You can go to design mode to drag/drop controls, right click on the controls to set correct properties etc. Then, click on the HTML mode to view the generated HTML. You can manually cmake changes to the automatically generated HTML. If you change any properties in HTML mode, the changes will be reflected when you switch to Design Mode

Solution Explorer

Solution Explorer, located on TOP RIGHT corner of VS.NET, displays your solution, all projects included in each solution and the list of files in each project. They are listed in the form of a tree control.

Typically, for a single application, you will have 1 solution and one or more projects. When you create a new application, you are have to create single Visual Studio project. In more complex applications, there may be more than one projects. All these projects are grouped into a single solution. Even if you do not create a solution separately, a solution will be automatically created for you.

To add a new file to your project, you can right click on the project name (JustTestis the project name in the picture) and choose the menu option Add. It will give you the option to choose a file type. You can choose an appropriate type.

For WinForms and WebForms, you can see the file in design mode and the code associated with it. Double click on any form and it will be opened in design mode. Right click on any form and select the menu option 'View Code' to view the code associate with the form.

Picture 3 : Solution Explorer

Picture 4 : Output
Output

Output window, located on BOTTOM LEFT corner of VS.NET, displays the result of your project compilation. When you compile your project, all errors, warnings and compilation results will be displayed in this window.

In addition to the Output window, they are few other windows located in the BOTTOM LEFT corner of VS.NET.

Task List - shows individual tasks. Typically, when you compile your project, all errors and warnings will be added to your task list. You can double click on any item in the task list to go directly to the code associated with the task

.Command Window - you can execute code statements here. When you are debugging, you can evaluate the value of any variables by typing ? followed by the variable name.

Find Results - when you search for any text in file(s) using VS.NET, the results will be displayed in this window.
Projects

VS.NET allows you to create several types of projects. Most of the time you will be using one of two categories:
Windows Application - to create any standard windows application.
ASP.NET Web Application - to create a web site.

Creating a Project

To create a new project, choose the main menu : File > New > Project.

It will give you several options. First you must select a type from the left side of the popup - you may choose Visual Basic Projects or Visual C# projects based on the language you plan to use for development.

After selecting a type, you choose a template from the right side. You may choose Windows Application, ASP.NET Web Application or any other templatebased on the nature of the application you want.

Picture 4 : Create new project
When you create a Windows Project or ASP.NET Web Project, VS.NET will add a sample file by default. You can simply Build your new project and see how it works.

Building a project

To try this, create a new Windows Project as explained above. It will create a sample form. Go to the main menu and select the menu item Build > Build Solution.

This process will compile all the files included in your project and show you the result in the Output window. If the result shows '0 failed', your build is success and your application is ready to deliver!!

To Run the application you just Built, go to the main menu and select Debug > Start Without Debugging. This will launch the application you just developed.

You can drag and drop several controls to the form and try running it.

When you compile (build) the code, if there is any errors or warnings, the details will be shown in the 'Task List' window. You can click on the specific item in this window to go directly to the line of code associated with the error.

Không có nhận xét nào: