52
Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

Embed Size (px)

Citation preview

Page 1: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

Visual Studio.NET

Part 2 dbg --- Using the

Integrated Development Environment

Page 2: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

2

Visual Studio.NET

• A development “shell” for creating applications– Visual designer– Context editor with Intellisense for typing code– Programming language compilers– Run/Debug environment

Page 3: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

3

Visual Studio.NET and the IDE

• Any C# application can be written with a simple text editor (such as Notepad) as long as the Framework Class Libraries (FCL) are present (as we saw in FormFromTextFile).

• Normally, however, it is much simpler to program and manage C# applications using the Visual Studio Integrated Development Environment (IDE).

FormFromIDE

Page 4: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

4

Starting Visual Studio.NET

1. Start Visual Studio.NET from a Desktop shortcut.

-or-

2. , Programs:

Page 5: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

5

Creating a New Project

Page 6: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

6

Select a Language

Page 7: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

7

Select a Template

Page 8: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

8

Assign Path and Meaningful Name

Page 9: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

9

The Visual Studio IDE

Page 10: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

10

Adjust the View in the IDE

• To undock a docked window so it floats on the screen, drag it by its title bar away from the edge of the application window or double-click its title bar. Double-click a window’s title bar to return the window to its default location.

• To hide a docked window, click its Auto Hide button. The window will be displayed as a tab at the edge of the screen. You can redisplay it by placing the mouse pointer over the tab.

• To return all windows to their original Visual Studio positions, choose Window, Reset Window Layout in the menu.

Page 11: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

11

Setting Default Location for Projects

• Choose Tools, Options in the menu.

• Click the + in front of Projects and Solutions.

• Click General under Projects and Solutions.

• Click the Browse button next to Visual Studio projects location: and choose the folder you created for this course.

Page 12: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

12

Visual Studio Solutions

• A solution is comparable to a workspace in C++ V6.

• The first project created in the solution gives its name to the solution and thus to the namespace as well.

• At times, it may be advisable to change the name of either the project or the namespace.

Page 13: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

13

The Designer View

• The IDE displays a design-time view of the visible portion, if any, of the object being designed.

• A Designer view of a form object appears by default in a new project.

• The form will be a window at run time.

Page 14: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

14

The Code View

• The IDE provides an editor for building the actual code for the class or classes that make up your new project.

• Pre-existing (library) code is not visible here.

• Choose View Code icon in Solution Explorer or click Code tab in Designer Window.

Page 15: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

15

Adjusting Properties at Design Time

• The IDE provides a convenient window for assigning values to object properties at design time.

• The Properties Window displays all available properties for any object that is selected within the IDE.

• Use F4 or View, Properties Window from menu, if the Properties Window is not visible.

Page 16: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

16

Some Form Properties

• A number of form properties can be changed at design time.

• Dimensions of the form can be adjusted by dragging the selection handles or by assigning values to the Size Property in the property window.

• The run time screen position of the window can be adjusted by choosing values for the StartPosition property.

Page 17: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

17

More Form Properties

• Every form should have a Text property that reflects the role of the form in the project; the text typed as the Text Property appears in the Titlebar of the window.

• The form icon can also be changed by assigning a new icon file to the Icon property; later, we will learn how to create a custom icon.

FormWithChangedProperties

Page 18: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

18

Compiling and Running

• Choose Build, Build Solution from menu to compile without running.

• 3 ways to run (and build, if necessary) an application:– Choose Debug, Start

Debugging from menu– Press F5– Click the Debug tool in the

toolbar

Page 19: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

19

Solution

.NET FrameworkVisual Studio .NET

Project

CommonLanguageRuntime

IntegratedDevelopmentEnvironment

Source files

C#compiler

1 2 3

Assembly

Intermediate Language (IL)

Class references

The Compilation Process

Page 20: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

20

The Window Control Box

• When the Windows Application project runs, the form appears as a Window object.

• The project remains running until the window is closed.

• The window can be closed by clicking the in the Control Box in the Titlebar.

Page 21: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

21

The Window Control Box

• The Control Box also contains icons for minimizing the window to a taskbar item and maximizing the window to full screen size.

• The Maximize icon becomes a Restore Down icon if the window is maximized.

• All, some, or none of these icons may be displayed by setting the ControlBox, MinimizeBox, and/or MaximizeBox properties to true or false.

ControlBox

Minimize

Maximize

Restore Down

Close

Page 22: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

22

Show in TaskBar

• You may not wish to have a Taskbar item appear to represent your window.

• Setting the Show in TaskBar property to False at design time will accomplish this.

Page 23: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

23

Let’s Review C++ File Structure

• Before looking at the C#.NET V2005 file structure of the project we just created, we’ll review how C++ V6 and .NET versions of projects look in My Computer.

Page 24: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

File Structure of a C++ V6 or .NET

Console Application

HW777.dsw or (.sln)

HW777.ncb

HW777.dsp

HW777.plg

HW777.opt

source.cpp

HW777.exe *

source.obj *

HW777.pdb

HW777.pch *

HW777.ilk

vc60.pdb

vc60.idb *

Note: Debug folder contains all 7 subfiles. Release folder only contains 4 asterisked subfiles.

HW777

Debug orRelease

Page 25: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

25

Let’s Review C# V2003 File Structure

• Before looking at the C#.NET V2005 file structure of the project we just created, we’ll review how C#.NET V2003 projects look in My Computer.

Page 26: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

File Structure of a C#.NETV2003 Windows Application

HW888.sln

App.ico

HW888.csproj

AssemblyInfo.cs

HW888.csproj.user

frmDiner.cs

HW888.exe

HW888.pdb

frmDiner.resx

HW888

Debugbin

obj

HW888.suo

Page 27: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

27

Structure of a C# Solution

• The IDE creates a collection of files called a solution.

• Normally, a solution contains one project.• A project generates an application.• Multiple projects may be contained within one

solution.

Page 28: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

28

C#.NET V2005 Solution Explorer Window

Page 29: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

29

Let’s Look at C# V2005 File Structure

• Now we’ll look at how the C#.NET V2005 project we just created looks in My Computer.

Page 30: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

30

File Structure of C#.NET V2005 Project

Page 31: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

HW999

bin

obj

Properties

Debug

HW999.sln

HW999.suo

HW999.csproj

HW999.exe

frmDeesDiner.cs

frmDeesDiner.Designer.cs

Program.cs

frmDeesDIner.resx

File Structure of a C#.NET V2005 Windows ApplicationHW999

Page 32: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

32

Important Files

• The project file (with an extension of .csproj) keeps track of the files that make up the project and records various settings for the project.

• The solution file (with an extension of .sln) 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.

Page 33: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

33

Form Files

• In C# 2005, each form is defined by two C# files. Each file contains a partial class. The file with the .cs extension contains the code that is entered by the programmer; the file with the Designer.cs extension contains the code that is generated when the programmer works with the Form Designer. When the project is compiled, these two partial classes are combined into a single class that determines the appearance and operation of the form.

Page 34: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

34

Other Files

• A source code file that doesn’t define a form is usually stored in a single C# source file that contains a single class.

• The References folder contains references to the assemblies for the namespaces that the application can use. These namespaces contain the classes that the project requires. In most cases, all the references that you need are included when the project is created.

Page 35: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

35

Opening a C#.NET V2005 Project from My Computer

• To open a project from My Computer, double-click the solution file (ex. Homework999.sln).

• The solution file (ex. Homework999.sln), which is a file that contains pointers to all Projects within a Solution, is now stored outside of the Project folder.

Page 36: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

36

Opening a C#.NET V2005 Project from Visual Studio.NET

Page 37: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

37

E-mailing Assignments to Professor

• When e-mailing an assignment to me, you must submit the circled folder and all of its contents.

You should “zip” this folder into 1 file for easy transmission using a program named WinZip.

If you don’t have WinZip, download it from downloads.com .

Page 38: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

38

“Zipping” a Folder via WinZip

1. Navigate to folder in My Computer.

2. Right-click and choose WinZip from context menu.

3. Choose 2nd option, Add to Homework999.zip .

4. One file, Homework999.zip, containing the contents of entire Homework999 folder, is created.

Page 39: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

39

Start a New E-mail Message

1. Start http://mail.strose.edu and click New message. Add professor e-mail address in To: area and assignment number in Subject: area.

Page 40: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

40

Adding .zip File as an Attachment

1. Click in message toolbar. You will see the Attachments dialog.

2. Browse for your .zip file.

Page 41: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

41

Adding .zip File as an Attachment

1. After the file name displays in Choose a file to attach box, click the Attach button.

2. The .zip file will then show as a Current File Attachment. Click the Close button.

Page 42: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

42

Send E-mail Message

• Your e-mail message should now display the attached .zip file.

• Send the e-mail message.

Page 43: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

Events

Application Lifetime and Object Responses to Stimuli

Page 44: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

44

Event-Driven Applications

• Objects can both send, and react to, special messages or stimuli called events.

• By and large, event-driven applications run until they are stopped by user intervention.

• Event driven applications respond to any events that they detect.

Page 45: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

45

Events

Event Occurs when…

Common control events

Click …the user clicks the control

Double-click …the user double-clicks the control

Enter …the focus is moved to the control

Leave ...the focus is moved from the control

Common form events

Load …the form is loaded into memory

Closing …the form is closing

Closed …the form is closed

Page 46: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

46

Reacting to a Click Event

• An object can react to the event caused by clicking the mouse.

• Objects react to events by executing code within a special method (function) called an event handler.

• A specific event (clicking this object) causes the function to run.

• Any instructions coded within the function are then executed.

FirstEvent

Page 47: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

47

Associating Handlers with Events

• An event handler is a method (function) that contains the code that will be executed when a particular event occurs for the a specific object.

• Event handlers may be associated with objects and their events in several ways:– The default handler for a control (often the Click event

handler) will be added automatically to the code area, when you double-click the control in the Designer View.

– Or, you may double-click a particular event in the Properties Window.

Page 48: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

48

Associating Events via the Property Window• A list of all available events for

an object is available in the Properties window if the is toggled.

• Double-click the appropriate event.

• Selecting an event here causes an event handler skeleton to be created in the code area.

Page 49: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

49

A New Handler Function

• Event Handler functions are named with a combination of the object and the event.

Page 50: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

50

“Event Wiring”

• A separate line of code is automatically written (in the Windows Generated Code region of the formName.Designer.cs file) to connect the event handler to the event. You can think of this as “event wiring” or “automatic registration” of the event handler function.

Page 51: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

51

Structure of a Handler

• An event handler is a void function with two arguments.

• The sender argument of type Object represents the originator of the event.

Page 52: Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment

52

Structure of a Handler

• The e argument of type EventArgs represents the set of data fields, if any, that arrive with the event.

• EventArgs fields vary with the class that originates, or raises, the event.