0% found this document useful (0 votes)
11 views

Unit 2

Uploaded by

Reethu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Unit 2

Uploaded by

Reethu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 79

Introduction to Visual

Studio 2008
Rapid Application Development.
• In Visual Studio 2008, developer productivity
doesn’t end with the code editor and wizards.
• It provides new tools and frameworks to
– simplify the tasks of developers, designers, and
database professionals for new application
architectures and platforms
• Visual Studio 2008 not only delivers a productive
development tool, but also enables developers to
tackle new business problems while decreasing
the total cost of solution construction.
Effective Team Collaboration
• Visual Studio 2008 enhances the end-to-end value
of Visual Studio Team System by
– increasing its role-based coverage
– delivering enhanced traceability throughout the
software development life cycle.
• With deep integration across roles in the software
life cycle and the Team Foundation Server, Team
System enables
– customers to amplify the impact of their teams
– improve software quality.
Breakthrough User Experience
• As users look for new ways to comprehend
and retain information, developers must still
grapple with basic desktop and application
security.
• Visual Studio, Windows Vista, and the 2007
Office system enable developers to deliver a
safe, robust, and compelling user experience
in any type of application.
• These fundamental advances enable customers to
rapidly create connected applications that deliver
the highest quality, rich user experiences regardless
of project complexity or organization size.
Start Page
Creating a New Project

Select Visual Select


Basic Windows
Projects Application

Specify project
name

Specify
location
Design View
Solution Explorer

Expanded
mode

Collapsed
mode
Form file

Continue 🡪
Properties Window
Categorized &
Alphabetic Property name
listing options

Expanded Property value


mode

Collapsed
mode
Saving Project
• File > Save All
• Do not use File > Save or Save As
• To copy a project, use Windows Explorer to copy the
entire project folder
Outline
• Install Visual studio 2008
• Visual Studio Environment
• Menu Bar and Toolbar
• Visual Studio .NET IDE Windows
• Solution Explorer
– Toolbox
– Properties Window
– Using Help
Install Visual Studio IDE
• Download Visual studio IDE from the internet.
• Opening Setup.exe

1- double click “Install Visual


Studio 2008.”
Install Visual Studio IDE Cont.

2- Review and accept


license terms.

3- confirm that the


Registration key and
computer name are
entered correctly. Click
Next.
Install Visual Studio IDE Cont.

4- Select the Custom radio button,


and then ensure that the Product
installation path is optimal. Then
Click Next
Install Visual Studio IDE Cont.

5- Make sure C# is checked, and


ensure that you have enough space
on your computer to complete the
install. Then Click install.
Install Visual Studio IDE Cont.

Visual Studio 2008 will begin its


installation on your computer!
Visual studio Environment
Overview of the VS.NET IDE
◼ User creates a new project in Visual Studio
▪ A solution and a folder are created at the same time with the same
name as the project
▪ The project belongs to the solution
▪ Multiple projects can be included in a solution
◼ Solution
▪ Contains several folders that define an application’s structure
▪ Solution files have a file suffix of .sln
◼ Project: contains files for a part of the solution
▪ Project file is used to create an executable application
▪ Every project has a type (Console, Windows, etc.)
▪ Every project has an entry point: A Sub procedure named Main or a
Form
Recent Projects

Getting start
(Help)

Compilation error and warning


Create New project

Select project type

Select programming
language in our case
(visual C#)

Project name and there location


1- Menu Bar and toolbar

4- Solution explorer

2- Tool Box 3- Properties


1- Menu Bar and toolbar
1- Menu Bar and toolbar
• The IDE provides windows for accessing project files
and customizing controls.

•These windows can be accessed via the toolbar icons or


by selecting the name of the desired window in the View
menu.
2- Toolbox
The Toolbox window contains controls
used to customize forms. Programmers
can “drag and drop” controls onto the
form.
3- Properties
The Properties window displays the properties for a
form or control. Properties specify information such as
size, color and position.

Properties Properties Value


3- Properties Cont

We called this properties label1


3- Properties Cont

We called this properties of button1


Button properties
Effect Property

Text

BackColor

Font

Location

Size
4- The solution explorer
Execute Program
• You can execute program using
toolbar icon

• When Visual Studio .NET begins


execution, the Start Page displays
Using Help
The Help menu contains a variety of commands,
which are summarized in the following table.
Using Help – Dynamic Help
In C# .NET the code you create is organized
using different layers of grouping :
– Solutions : contain one or more projects.
– Projects : contain more than one file.
– Files.
• Solution Explorer : provides access to all the
files in a solution.
• ToolBox : contains controls used to customize
forms.
• Properties Window : displays the properties
for a form or a control.
Class Hierarchies
Class View Window
• Class View displays the symbols defined, referenced,
or called in the application being developed.
• Open Class View from the View menu.
• There are two panes:
– an upper Objects pane
– a lower Members pane.
• The Objects pane contains an expandable tree of
symbols whose top-level nodes represent projects.
• To expand a node selected in the tree, click its plus (+)
sign or press the plus (+) key on the keypad.
Object Browser
• In the Object Browser, available objects
(namespaces, types, interfaces, enumerations,
and other containers) can be expanded to
reveal ordered lists of their members (classes,
properties, methods, events, constants,
variables, and other contained items).
Class diagrams
• Class diagrams help to understand the class
structure of projects others have written (or
that you wrote a long time ago).
• They can be used to customize, share and
present project information with others.
To add a blank class diagram to a
project
• In Solution Explorer, right-click the project name. Then
choose Add New Item or Add, New Item.
• Under Templates, choose Class Diagram. For Visual C+
+ projects, look under Templates, and then under
Utility to find this template.
• The class diagram opens in Class Designer and appears
as a file that has a .cd extension in Solution Explorer in
the project hierarchy. Use the Class Designer toolbox
to drag shapes and lines to the diagram.
• To add multiple class diagrams, repeat the steps in this
procedure.
To add a class diagram based on
existing types
• In Solution Explorer, open the class file context
menu, then choose View Class Diagram.
• -or-
• In Class View, open the namespace or type
context menu, then choose Class Diagram
Class Details
• Class Details is a window used to configure the members of a type.
• By default, the Class Details Window appears automatically when
you open a new class diagram
• It is also possible to open the Class Details window explicitly, in the
following ways.

• To open the Class Details window

• Right-click the surface of a class diagram to display a context


menu.
• In the context menu, click Class Details Window.
• – or -
• Point to Other Windows on the View menu and then click Class
Details.
Class Diagram Toolbox
• Class diagrams have a toolbox
• The topmost buttons of the toolbox add new
types to the class diagram and application
• You can add a new class, enumeration,
interface, abstract class, structure or delegate
• Double-clicking one of these “new type”
buttons adds the new type to the application,
and the new type then is displayed in the class
diagram
Inheritance
• To create an inheritance relationship between
two types on a class diagram using Class
Designer, connect the base type with its
derived type or types.
• We can have an inheritance relationship
between two classes, between a class and an
interface, or between two interfaces.
To create an inheritance between
types
• From your project in Solution Explorer, open a class diagram
(.cd) file.
• If you don't have a class diagram, create it.
• In the Toolbox, under Class Designer, click Inheritance.
• On the class diagram, draw an inheritance line between the
types that you want, starting from:
– A derived class to the base class
– An implementing class to the implemented interface
– An extending interface to the extended interface
• Optionally, when you have a derived type from a generic
type, click the inheritance line.
• In the Properties window, set the Type Arguments property
to match the type that you want for the generic type.
Association
• Association lines define “has a “ relationship,
where one type has a member that is another
type.
• To create a new relationship in a class
diagram, select the Association button in the
toolbox
• Click the outer type and drag the association
line from the outer type to the inner
(embedded) type.
Error List Window
• Error List Window displays errors and
warnings from the compiler and linker
• Each type of message has a unique icon
– Eg., an error message is decorated with a red
circle that contains an “x”
Code Editor
• Used by developers to
– Enter
– Delete
– Format
– Edit code
• From the code editor window
• Code editor includes features such as
– IntelliSense
– Code snippets
– Smart tags
– Formatting options
IntelliSense
• IntelliSense is a powerful feature that can
significantly increase your productivity because it
provides logical code elements that you can select
from a drop-down menu when you are coding.
• It is designed to make the development of your
application much easier by helping you
automatically generate code in the Code Editor.
• This process can reduce the time that you spend
typing and help you avoid introducing
typographical errors in your code
Source code Formatting
• Visual studio 2008 provides excellent control
of code formatting
• Can control code indentation, line spacing,
code spacing, and the wrapping of blocks
• Done in the Option dialog box on the Tools
menu
• Expand the Text Editor node in the left-hand
pane and then select the C# node
Change tracking
• Distinguishes saved from unsaved code
• Visual Studio 2008 displays a colored bar on
the left of the Code Editor window to indicate
the code status
• Saved code has a green bar
• Unsaved code has a yellow bar
• Original code, which is code that is unchanged
since the source file was opened, has no
colored bar at all
Code Snippets
• A code snippet is a block of reusable code that
you can insert where you need it in your code.
• Snippets can be simple or more complex
—for example, blocks such as try-finally, while and
if-else are commonly used default snippets
• Three kinds of snippets
– Expansion – Inserts code at the cursor
– Surround With – Envelops selected code
– Refactoring – used with refactoring
Insert a Code Snippet
• Open a code file and put the cursor where you want to
insert the code snippet.
• Bring up the code snippet menu in one of three ways:
– Press CTRL+K, CTRL+X.
– On the Edit menu, point to IntelliSense, and then click Insert
Snippet.
– Right-click the mouse and then select the Insert Snippet
command on the shortcut menu.
• Select the code snippet from the code snippet inserter and
then press TAB or ENTER, or double-click the snippet.
• If you type the first few letters of the snippet, your selection
will be moved down to that point in the list.
To use code snippets through the
snippet’s shortcut
• Put the cursor where you want to insert the
code snippet.
• Type the shortcut for the code snippet that
you want to add to your code.
• OR –
• Type the first few letters of the shortcut and
then press either CTRL+SPACE (C#) to view the
completion list, and then select the snippet
shortcut from the list.
Default Snippets
• Default snippets appear in the IntelliSense completion
list and the code snippet picker
– #if
– #region
– ~ inserts a destructor
– class inserts a class definition
– do surrounds a code with a do while block
– for
– if
– switch
– try
– while
Code Snippet Manager

• To view information about the code snippets


that are currently installed, choose Code
Snippets Manager on the Tools menu and then
select the programming language you want to
examine.
• In the Code Snippet Manager dialog box, you
can also add or remove snippet directories, or
import more snippets.
Creating Snippet
• You can create a code snippet with only a few
steps.
• Create an XML file, fill in the appropriate
elements, and add your code to it.
• You can also add references and replacement
parameters to your code.
• You can add the snippet to your Visual Studio
installation by using the Import button on the
Code Snippets Manager (Tools/Code Snippets
Manager).
Snippet Template
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title></Title>
</Header>
<Snippet>
<Code Language="">
<![CDATA[]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
To Create a Code Snippet
• Create a new XML file in Visual Studio and add the template shown
above(prev slide).
• Fill in the title of the snippet, e.g. "Hello World ", in the Title
element.
• Fill in the language of the snippet in the Languages attribute of the
Code element.
– For this example, use “C#".
• Add some code in the CDATA section inside the Code element, for
example:

<Code Language=“C#">
<![CDATA[Console.WriteLine("Hello, World!")]]>
</Code>

• Save the snippet as C#CodeSnippet.snippet.


To Add a Code Snippet to Visual
Studio
• You can add your own snippets to your Visual Studio
installation by using the Code Snippets Manager.
• Open the Code Snippets Manager (Tools/Code Snippets
Manager).
• Click the Import button.
• Go to the location where you saved the code snippet in the
previous procedure, select it, and click Open.
• The Import Code Snippet dialog opens, asking you to
choose where to add the snippet from the choices in the
right pane.
• One of the choices should be My Code Snippets.
• Select it and click Finish, then OK.
• The Header element should look something like this:
<Header>
<Title>Hello World</Title>
<Author>Myself</Author>
<Description>Says Hello to the world.</Description>
</Header>
• Open the Code Snippets Manager and select your
code snippet.
• In the right pane you should see that the Description
and Author fields are now populated.
Refactoring
• Refactoring is the process of improving your
code after it has been written by changing the
internal structure of the code without
changing the external behavior of the code.
• Visual C# provides the following refactoring
commands on the Refactoring menu:
• Extract Method Refactoring
• Rename Refactoring
• Encapsulate Field Refactoring
• Extract Interface Refactoring
• Remove Parameters Refactoring
• Reorder Parameters Refactoring
Extract Method
• Extract Method is a refactoring operation that
provides an easy way to create a new method from a
code fragment in an existing member.
• Using Extract Method, you can create a new method
by extracting a selection of code from inside the code
block of an existing member. The new, extracted
method contains the selected code, and the selected
code in the existing member is replaced with a call to
the new method. Turning a fragment of code into its
own method lets you quickly and accurately reorganize
code for better reuse and readability.
• Extract Method has the following benefits:
• Encourages best coding practices by emphasizing
discrete, reusable methods.
• Encourages self-documenting code through good
organization.
• When descriptive names are used, high-level methods
can read more like a series of comments.
• Encourages the creation of finer-grained methods to
simplify overriding.
• Reduces code duplication.
To use Extract Method
1. Create a console application named ExtractMethod, and then replace Program with
the following example code.
class A
{
const double PI = 3.141592;
double CalculatePaintNeeded(double paintPerUnit, double radius)
{
// Select any of the following:
// 1. The entire next line of code.
// 2. The right-hand side of the next line of code.
// 3. Just "PI *" of the right-hand side of the next line
// of code (to see the prompt for selection expansion).
// 4. All code within the method body.
// ...Then invoke Extract Method.
double area = PI * radius * radius;
return area / paintPerUnit;
}
}
2. Select the code fragment you want to extract:

double area = PI * radius * radius;


3. On the Refactor menu, click Extract Method.
The Extract Method dialog box appears.
Alternatively, you can also type the keyboard shortcut
CTRL+R, M to display the Extract Method dialog box.
You can also right-click the selected code, point to Refactor,
and then click Extract Method to display the Extract
Method dialog box.
4. Specify a name for the new method, such as CircleArea, in
the New Method Name box.
A preview of the new method signature displays under
Preview Method Signature.
5. Click OK.
Rename Refactoring
• Rename is a refactoring feature in the Visual
Studio integrated development environment
(IDE) that provides an easy way to rename
identifiers for code symbols such as fields,
local variables, methods, namespaces,
properties, and types.
• Rename can be used to change the names in
comments and in strings and to change the
declarations and calls of an identifier.
Encapsulate Field Refactoring
• Creates a property that abstracts the selected
field
Extract Interface Refactoring
• Extract Interface is a refactoring operation
that provides an easy way to create a new
interface with members that originate from an
existing class, struct, or interface.
Remove Parameters Refactoring
• Remove Parameters is a refactoring operation
that provides an easy way to remove
parameters from methods, indexers, or
delegates. Remove Parameters changes the
declaration; at any locations where the
member is called, the parameter is removed
to reflect the new declaration.
Reorder Parameters Refactoring
• Reorder Parameters is a Visual C# refactoring
operation that provides an easy way to change
the order of the parameters for methods,
indexers, and delegates. Reorder Parameters
changes the declaration, and at any locations
where the member is called, the parameters
are rearranged to reflect the new order
Building and Deployment
• The Microsoft Build Engine (MSBuild) is the build
environment for Visual Studio.
• After you have completed building your C# application, the
next step is to distribute it.
• C# is a .NET language; therefore, distributing any C#
executables to other machines requires the .NET
Framework to be installed on each execution machine (and
possibly other dependencies specific to your application).
• Moving completed applications to other computers is
generally referred to as deployment.
• The Microsoft development environment provides
mechanisms for deployment;

You might also like