Sei sulla pagina 1di 12

Lesson 1.

3
An Introduction to Visual Studio
DATA INPUT
This chapter gets you started with Visual Studio 2008 by introducing the .NET Framework, the languages
that work with the .Net Framework, and the Visual Studio development environment. It also gives a
quick tour of this development environment. Along the way, you’ll learn all the concepts and terms that
you need for developing .Net applications.

An Introduction to .NET Development


This section presents some of the concepts and terms that you need before you begin developing .NET
applications. Although this section focuses on the Visual Basic programming language, most of these
concepts and terms also apply to other .Net programming language.

Windows Form
Visual Studio can be used to develop different types of applications; one of these is the Windows Forms
applications. A Windows Forms application (WinForms app) is a typical Windows application that
runs on the user’s PC. Each Windows form (just form) in the application provides a user interface that
lets the user interact with application. In the example below, the application consist of a single form that
lets the user perform either of two calculations; a future value or a monthly investment calculation. Many
applications, though, require more than one form.

As part of the user interface, a windows form application uses Form controls. For instance, the form on
the figure above uses group box, radio buttons, labels, textboxes and buttons. In this chapter you’ll start
learning how to develop Windows Forms applications.

DESCRIPTION
 A Windows Forms application (Windows application) runs in its window and consists of one or
more Windows Forms that provide the user interface.
 Each Windows form contains Windows Forms controls like labels, textboxes, buttons, radio
buttons and group box. These controls let the user interact with the application.

1|Page
Programming Languages Supported by Visual Studio 2008

Language Description
Visual Basic Designed for rapid application development
Visual C# Combines the feature of Java and C++ and is suitable for rapid
application development
Visual C++ Microsoft’s version of C++
Visual F# Combines functional, procedural, and object-oriented
programming

Platforms that can Run Visual Studio 2008

 Windows XP, Windows Vista, Windows 7, Windows 8, Windows 10, or later releases of Windows
operating system

The .NET Framework

To give you more detailed view of the .NET Framework, the figure below presents its main components.
As you can see, the .Net Framework provides a common set of services that application programs
written in a .NET language such as Visual Basic can use to run on various operating systems and
hardware platforms. The .NET Framework is divided into two main components: the .NET Framework
Class Library and the Common Language Runtime.

The .NET Framework Class Library consist of segments of pre-written code called classes that
provide many of the functions that you need for developing .NET applications. On the other hand, the
ASP.NET classes are used for developing Web Forms applications. And other classes let you work with
databases, manage security, access files, and perform many other functions.

Although, it’s not apparent in the figure below, the classes in the .NET Framework Class Library are
organized in hierarchical structure. Within thus structure, related classes are organized into groups
called namespaces. Each namespace contains the classes used to support a particular function. For
example, the System.Windows.Forms namespace contains the classes used to create forms and the
System.Data namespace contains the classes you use to access data.

The Common Language Runtime (CLR) provides the services that are needed for executing any
application that is developed with one of the .NET languages. This is possible because all of the .NET
languages compile to a common intermediate language, which you’ll learn more in this chapter. The CLR
also provides the Common Type System that defines the data types that are used by all .NET languages.
Because all of the .NET applications are managed by the CLR, they are sometimes referred to as managed
applications.

If you’re new to programming, you might not understand the diagram below completely, but that’s
alright. For now, all you need to understand is the general structure of the .NET Framework and the
terms that have been presented so far. As you progress, the diagram below will make more sense, and you
will become more familiar with each of the terms.

2|Page
DESCRIPTION

 Windows Forms applications do not access the operating system or the computer hardware
directly. Instead, they use services of the .NET Framework, which in turn access the operating
system and hardware.
 The .NET framework consists of two main components: the .NET Framework Class Library and
the Common Language Runtime.
 The .NET Framework Class Library provides files that contain pre-written code known as classes
that are available to all of the .NET programming languages. This class library consists of
thousands of classes, but you can create simple .NET applications once you learn how to use just a
few of them.
 The Common Language Runtime, or CLR, manages the execution of .NET programs by
coordinating essential functions such as memory management, code execution, security, and
other services. Because .NET applications are managed by CLR, they are called managed
applications.
 The Common Type System is a component of the CLR that ensures that all .NET applications use
the same basic types no matter what programming languages are used to develop the applications.

3|Page
The Visual Studio IDE

In practice, this IDE is often referred to simply as Visual Studio. You already know that this IDE
supports all four languages and you should realize that this IDE works with the .NET Framework.

Visual Studio includes designers that can be used to design user interface for Windows Forms. These
visual tools make this tough task much easier. It also includes editor that can be used to work with any of
the four languages. The editor contains many features that make it easy to enter and edit codes for an
application.

DESCRIPTION

 The Visual Studio IDE is often referred to as Visual Studio, even though that name is also used to
refer to the entire suite of products, including the .NET Framework.
 Visual Studio supports all four languages; Visual Basic, C#, C++ and F#.
 Visual Studio includes designers that can be used to develop Windows Forms applications and
Web Forms applications.
 Visual Studio includes a code editor that can be used to write the codes to build applications.

4|Page
How a Visual basic application is Compiled and Run

The diagram above show how a Visual Basic application is compiled and run. To start, you use Visual
Studio to create a project, which is made up of source files that contain Visual Basic statements. A project
may also contain other types of files, such as sound, image, or text files.

After you enter the Visual Basic code for a project, you use the Visual Basic compiler, which is built into
Visual Studio, to build (compile) your Visual Basic source code into Microsoft Intermediate
Language (MSIL). For short, this can be referred to as Intermediate Language (IL).

At this point, the Intermediate Language is stored on disk in a file that’s called as assembly. In addition to
the IL, the assembly includes the references to the classes that the application requires. The assembly can
then be run on any PC that has the Common Language Runtime installed on it. When the assembly
is run, the CLR converts the IL to native code that can be run by the Windows operating system.

Incidentally, a solution is a container that can hold one or more projects. Although a solution can
contain more than one project, the solution for a simple application usually can contain just one project.
In that case, the solution and the project are essentially the same thing.

5|Page
How Visual Basic Differs from the Other .Net Languages

Visual Basic uses the same .NET Framework classes as the other .NET programming languages. These
classes affect almost every aspect of programming, including creating and working with forms and
controls, using databases, and working with the basic language features such as arrays and strings. In
addition, Visual Basic works with the same Visual Studio IDE as the other .NET languages. As a result,
Visual Basic has many similarities to the other .NET languages. The main difference is the syntax of the
language.

Project and Solution Concepts

 Every Visual Basic project has a project file with an extension of vbproj that keeps track of the
files that make up the project and records various settings for the project.
 Every solution has a solution file with an extension of sln that keeps track of the projects that
make up the solution.
 When you open a project file, Visual Studio opens the solution that contains the project. And
when you open a solution file, Visual Studio automatically opens all the projects contained in the
solution. So either way, both the project and the solution are opened.
 Sometimes the project and solution files are stored in the same directory. Sometimes the project
file is stored in a subdirectory of the directory that contains the solution file.

UNDERSTANDING THE ENVIRONMENT

The Form Designer

The figure below is the Form Designer used to develop the user interface for a form. It also shows some
of the other windows that you use to develop Visual Basic applications. To add controls to a form, for
example, you use the Toolbox. To set the properties of a form or a control, you use the properties window.
And to manage the files that make up a solution, you can use the solution explorer.

This figure also points out two of the toolbars that are available from Visual Studio. You can use these
toolbars to perform a variety of operations. Of course, you can also perform any operation by using the
menus at the top of Visual Studio. And you can perform some operations using the context-sensitive
shortcut menu that’s displayed when you right-click on an object within Visual Studio.

6|Page
Toolbox

The toolbox handles all the objects used in a project form. It is categorized as shown below. Click the
desired category to see the available object controls.

7|Page
Solution Explorer

The Solution Explorer window provides easy access to all forms associated with your project. You can
easily view its codes and properties in just one click.

Properties Window

The Properties window is used to view and set the properties of objects. This can be seen on the right side
of the design environment. It is perhaps the most important window in the IDE, since it is the one used
most often. The ideal computer display resolution should be at 1024 x 768 to view the entire properties
window.

To change the resolution, right-click the Desktop, then click Properties, a Display Properties window will
appear. Click the Setting tab then adjust the Screen Resolution option located below the dialog box.

8|Page
Error List Window

The Error List window shows all error messages, warnings, and suggestions in a program after compiling.
It may also indicate the line of code where the error occurs.

DESCRIPTION

 The main Visual Studio contains one or more tabbed windows. To develop a form, you use the
Form Designer window (Form Designer). To develop code, you use the Code Editor Window.
 To add controls and other items to a form, you use the Toolbox. The toolbox contains a variety of
items organized into categories such as Common Controls, Containers, Menus and Toolbars, data
and so on.
 To change the way a form or control looks or operates, you use the Properties window. This
window displays the properties of the item that’s selected in the Form Designer.
 You use the Solution Explorer window to manage projects files.
 Several toolbars are available from Visual Studio. The standard toolbar includes standard
Windows toolbar buttons such as Open, Save, Cut, Copy and Paste, plus other buttons that you’ll
learn about as you progress in this course.
 To display any toolbar, right-click in an empty toolbar area and select the toolbar you want to
display.

The Code Editor

If you want to work with the source code for an application, you can use the Code Editor window (Code
Editor). The Code Editor lets you enter and edit the source code for a Visual Basic application.

After you have designed the user interface for a project by using the Form Designer to place controls on
the form, you can use the Code Editor to enter and edit the Visual Basic Code that makes the controls
work the way you want them to. the easiest way to call up the Code Editor is to double-click a control.
Then, you can begin typing the Visual Basic statements that will be executed when the user performs the
most common action on that control. If you double-click a button, for example, you can enter the
statements that will be executed when the user clicks on that button.

The Code Editor works much like any other text editor. However, the Code Editor has a number of special
features that simplify the task of editing Visual Basic code. For example, color is used to distinguish
Visual Basic keywords from variables, comments, and other language elements. And many types of
coding errors are automatically identified as you type so you can correct them.

9|Page
DESCRIPTION

 The Code Editor window (Code Editor) is where you create and edit the Visual Basic code that
your application requires. The Code Editor works much like any other text editor, so you
shouldn’t have much trouble learning how to use it.
 You can display the Code Editor by double-clicking the form or one of the controls in the Form
Designer window. Or, you can select the form in the Solution Explorer and click the View Code
button.
 Once you’ve opened the Code Editor, you can return to the Form Designer by clicking the Design
tab for that window or the View Designer button in the Solution Explorer (to the right of the View
Code button). You can also move among these windows by pressing Ctrl+Tab or Shift+Ctrl+Tab,
or by selecting a form from the Active Files drop-down list that’s available to the right of the tabs.
 It’s important to realize that the Form Designer and the Code Editor give you two different views
of a form. The Form Designer gives you a visual representation of the form. The Code Editor
shows you the Visual Basic code that makes the form wok the way you want it to.

How to Test a Project

When you develop a project, you design the forms using the Form Designers and you write the Visual
Basic code for the project using the Code Editor. Then, when you’re ready to test the project to see
whether it works, you need to build and run the project.

Building a Project

One way to do that is to pull down the Build menu and select the Build Solution command. If the project
doesn’t contain any coding errors, the Visual Basic code is compiled into the Intermediate Language for
10 | P a g e
the project and it is saved on disk in an assembly. This assembly can then be run by the common
Language Runtime.

Usually, though, you don’t need to build a project this way. Instead, you can simply run the project. Then,
if the project hasn’t been built before, or if it’s been changed since the last time it was built, Visual Studio
builds it before running it.

Running a Project

The easiest way to run a project is to click the Start Debugging button. Then, the project is built if
necessary, the Intermediate Language is executed by the Common Language Runtime, and the first form
of the project is displayed.

To test the project, you try everything that the application is intended to do. When data entries are
required, you try ranges of data that tests the limits of the application. When you’re satisfied that the
application works under all conditions, you can exit from it by clicking on the Close Button in the upper
right corner of the form or on a button control that has been designed for that purpose. If the application
doesn’t work, of course, you need to fix it.

SUMMARY

 Visual Studio can be used to develop different types of applications; one of these is the Windows
Forms applications.
 Windows Forms application (WinForms app) is a typical Windows application that runs on the
user’s PC.
 Visual Studio includes designers that can be used to design user interface for Windows Forms.
 The Form window (or just plain "form") is where you place objects that will be seen by the user.
 The Solution Explorer window, in the upper-right corner, shows the filenames of all of the forms
that are contained in your current project.
 The Properties window, in the lower right-corner, allows you to set most any property of the
object which is currently selected in the form window.
 The Toolbox usually appears along the left edge of the screen. It contains icons for tools that you
use to place objects on a form. You can double click an icon to place an object to appear on the
current form. You can pass your mouse over each tool to see the name of the tool appear in a pop-
up window.
 The main Visual Basic window holds the menu bar (across the top) and the Toolbar (across the
top of the screen just under the menu bar). The Toolbar contains the green Run button that we
use to execute our programs.
 The Help menu is a very useful and often overlooked repository of information. Use the online
Help to learn about Visual Basic.
 Visual Studio has a Code Editor that lets you enter and edit the source code for a Visual Basic
application.

11 | P a g e
 Each form in a VB project is a file that uses a .vb file extension. Forms are the windows that the
user will see during program execution. A form file contains references to the objects and their
properties that are located on the particular form. That is, if you accidentally delete a form file,
you lose all of the objects that were placed on that form. A form file is sometimes called a form
module in VB.
 A .sln solution file is saved for each VB project that you create. This is the file that you should
double-click in order to open a VB project that you previously saved. The icon for this file has the
number 10 in the upper-right corner.
 A .exe executable file that is stored in the bin folder. This file contains binary code (i.e. machine
code, 1's and 0's) that the computer uses to execute your program. Anyone with a Windows
computer can double-click this file icon in order to execute your program. But this file cannot be
used to view your actual source code.

TECH WORDS OVERVIEW


 .NET Framework— It is a software framework developed by Microsoft that runs primarily on
Microsoft Windows. It includes a large class library known as Framework Class Library (FCL) and
provides language interoperability (each language can use code written in other languages) across
several programming languages. The .NET Framework provides a comprehensive programming
model for building all kinds of applications on Windows, from mobile to web to desktop
 Visual Studio— It is a comprehensive collection of developer tools and services to help you
create apps for the Microsoft platform and beyond.
 Windows Forms Application— It is a graphical (GUI) class library included as a part of
Microsoft .NET Framework, providing a platform to write rich client applications for desktop,
laptop, and tablet PCs.
 Integrated Development Environment— A software application that provides
comprehensive facilities to computer programmers for software development. An IDE normally
consists of a source code editor, build automation tools and a debugger.
 Namespace— It is used to organize a group of classes in the language library; the hierarchy used
to locate the class. No two classes may have the same name within a namespace.
 Class— A prototype or blueprint for an object; includes specifications for the properties and
methods.
 Common Language Runtime— The virtual machine component of Microsoft's .NET
framework that manages the execution of .NET programs. A process known as just-in-time
compilation converts compiled code into machine instructions which the computer's CPU then
executes.
 Managed Application— A computer program source code that requires and will execute only
under the management of a Common Language Runtime virtual machine.
 Project— It is a collection of files created in Visual Studio.
 Solution— A Visual Basic application; can consist of one or more projects.

12 | P a g e

Potrebbero piacerti anche