Overview on NET NET is not a single

  • Slides: 71
Download presentation
Overview on. NET • . NET is not a single programming language. • It

Overview on. NET • . NET is not a single programming language. • It includes: • • Visual Basic Visual J# Visual C++ Visual C# • All these languages has the same source code

Why all these programming languages in. NET? • There are several programmers that are

Why all these programming languages in. NET? • There are several programmers that are sensitive to the programming languages they love • We can make programming team, with different. NET programming language. • Some programming has a strong points that preferable by people

Visual Studio, . NET, and the IDE • Visual Studio 2008 is a suite

Visual Studio, . NET, and the IDE • Visual Studio 2008 is a suite of products that includes the. NET Framework 3. 5 and the Integrated Development Environment (IDE) you will be using • The. NET Framework supports four programming languages • Visual Basic, Visual C#, Visual C++, Visual J# • Also COBOL, with more to come • The Visual Studio IDE is your interface to. NET -it is used to develop applications in any of the supported programming languages 1/16/2010 12: 05 PM

The. NET Framework • Provides a common set of services that can be used

The. NET Framework • Provides a common set of services that can be used when programming in any supported language • Enables you to write programs that run on any operating system on any hardware platform • Main components … • . NET Framework Class Library (FCL) • Common Language Runtime (CLR) 1/16/2010 12: 06 PM

The. NET Framework (raising the bar) 1/16/2010 12: 07 PM

The. NET Framework (raising the bar) 1/16/2010 12: 07 PM

Introduction to The Integrated Development Environment • Sometimes the IDE is referred to as

Introduction to The Integrated Development Environment • Sometimes the IDE is referred to as Visual Studio – but it is only one part of VS • The IDE is the interface between the programmer and the. NET tools he or she uses • Includes design components for Console, Web, and Windows development (to name a few) • Includes an editor for all. NET languages as well as XML and HTML 8/10/2008 6: 34 PM

Initial Visual Basic Screen Chapter 2 - VB 2008 by Schneider 7

Initial Visual Basic Screen Chapter 2 - VB 2008 by Schneider 7

Chapter 2 –Visual Basic, Controls, and Events • 2. 1 An Introduction to Visual

Chapter 2 –Visual Basic, Controls, and Events • 2. 1 An Introduction to Visual Basic • 2. 2 Visual Basic Controls • 2. 3 Visual Basic Events Chapter 2 - VB 2008 by Schneider 8

2. 1 An Introduction to Visual Basic 2008 • Why Windows and Why Visual

2. 1 An Introduction to Visual Basic 2008 • Why Windows and Why Visual Basic -(GUIs), icons, Menues, buttons - Comparing it with DOS • How You Develop a Visual Basic Application • The Different Versions of Visual Basic Chapter 2 - VB 2008 by Schneider 9

Visual Basic 2008 • Language used to create Windows applications. • Provides a Graphical

Visual Basic 2008 • Language used to create Windows applications. • Provides a Graphical User Interface or GUI. • The sequence of instructions executed in the program is controlled by events. Chapter 2 - VB 2008 by Schneider 10

Sample Input Screen Chapter 2 - VB 2008 by Schneider 11

Sample Input Screen Chapter 2 - VB 2008 by Schneider 11

How to Develop a Visual Basic Application • Designing the screen of VB project,

How to Develop a Visual Basic Application • Designing the screen of VB project, is a key element of planning VB program • Design the Interface for the user. • Determine which events the controls on the window should recognize. • Write the event procedures for those events. Chapter 2 - VB 2008 by Schneider 12

Different Versions of Visual Basic • • Version 1. 0 – 1991 Version 2.

Different Versions of Visual Basic • • Version 1. 0 – 1991 Version 2. 0 – 1992 Version 3. 0 – 1993 Version 4. 0 – 1995 Version 5. 0 – 1997 Version 6. 0 – 1998 Visual Basic. NET – 2002 (NOT BACKWARD COMPATIBLE WITH EARLIER VERSIONS) • Visual Basic 2005 – November 2005 • Visual Basic 2008 – November 2007 Chapter 2 - VB 2008 by Schneider 13

2. 2 Visual Basic Controls • • Invoking Visual Basic Text Box Control Button

2. 2 Visual Basic Controls • • Invoking Visual Basic Text Box Control Button Control Label Control List Box Control Name Property Help / Fonts / Auto Hide Positioning and Aligning Controls Chapter 2 - VB 2008 by Schneider 14

Visual Basic Start Page Chapter 2 - VB 2008 by Schneider 15

Visual Basic Start Page Chapter 2 - VB 2008 by Schneider 15

Start a New Project Chapter 2 - VB 2008 by Schneider 16

Start a New Project Chapter 2 - VB 2008 by Schneider 16

New Project Dialog Box Chapter 2 - VB 2008 by Schneider 17

New Project Dialog Box Chapter 2 - VB 2008 by Schneider 17

Initial Visual Basic Screen Chapter 2 - VB 2008 by Schneider 18

Initial Visual Basic Screen Chapter 2 - VB 2008 by Schneider 18

Toolbox Chapter 2 - VB 2008 by Schneider 19

Toolbox Chapter 2 - VB 2008 by Schneider 19

3 Ways to Place a Control from the Toolbox onto the Form Window •

3 Ways to Place a Control from the Toolbox onto the Form Window • Double-click • Drag and Drop • Click, Point, and Drag Chapter 2 - VB 2008 by Schneider 20

Four Controls at Design Time Text box To select a control, click on it.

Four Controls at Design Time Text box To select a control, click on it. Sizing handles will appear when a control is selected. Chapter 2 - VB 2008 by Schneider 21

Text Box Control • Used for input and output • When used for output,

Text Box Control • Used for input and output • When used for output, Read. Only property is set to True Tasks button Sizing handles Chapter 2 - VB 2008 by Schneider 22

Properties Window Press F 4 to display the Properties window for the selected control.

Properties Window Press F 4 to display the Properties window for the selected control. Categorized view Alphabetical view Chapter 2 - VB 2008 by Schneider 23

Properties Window Selected control Properties Settings Chapter 2 - VB 2008 by Schneider 24

Properties Window Selected control Properties Settings Chapter 2 - VB 2008 by Schneider 24

Some Often Used Properties • • Text Autosize Font. Name Font. Size Fore. Color

Some Often Used Properties • • Text Autosize Font. Name Font. Size Fore. Color Back. Color Read. Only Chapter 2 - VB 2008 by Schneider 25

Setting Properties • Click on property name in left column. • Enter its setting

Setting Properties • Click on property name in left column. • Enter its setting into right column by typing or selecting from options displayed via a button or ellipses. Chapter 2 - VB 2008 by Schneider 26

Setting the Text Property 1. Click on Text property. 2. Type your first name

Setting the Text Property 1. Click on Text property. 2. Type your first name Chapter 2 - VB 2008 by Schneider 27

Setting the Fore. Color Property 1. Click on Fore. Color. 2. Click on button

Setting the Fore. Color Property 1. Click on Fore. Color. 2. Click on button at right of settings box. 3. Click on Custom tab to obtain display shown. 4. Click on a color. Chapter 2 - VB 2008 by Schneider 28

Font Property 1. Click on Font in left column. 2. Click on ellipsis at

Font Property 1. Click on Font in left column. 2. Click on ellipsis at right of settings box to obtain display shown, 3. Make selections. Chapter 2 - VB 2008 by Schneider 29

Button Control • The caption on the button should indicate the effect of clicking

Button Control • The caption on the button should indicate the effect of clicking on the button. • Text property determines caption. Chapter 2 - VB 2008 by Schneider 30

Add an "access key" Chapter 2 - VB 2008 by Schneider 31

Add an "access key" Chapter 2 - VB 2008 by Schneider 31

Label Control • Used to identify the contents of a text box. • Text

Label Control • Used to identify the contents of a text box. • Text property specifies caption. • By default, label automatically resizes to accommodate caption on one line. • When the Auto. Size property is set to False, label can be resized manually. Used primarily to obtain a multi-rowed label. Chapter 2 - VB 2008 by Schneider 32

List Box Control • Initially used to display several pieces of output. • In

List Box Control • Initially used to display several pieces of output. • In Chapter 9 used to select from a list. • Does not have a Text property • Items property Chapter 2 - VB 2008 by Schneider 33

The Name Property • Used by the programmer to refer to a control in

The Name Property • Used by the programmer to refer to a control in code • Setting for Name property near top of Properties window. • Name must begin with a letter, be less than 215 characters long, and may include numbers and letters. • Use appropriate 3 - or 4 -character naming prefix Chapter 2 - VB 2008 by Schneider 34

Control Name Prefixes Control Prefix Example button btn. Compute label lbl. Address text box

Control Name Prefixes Control Prefix Example button btn. Compute label lbl. Address text box txt. Address list box lst. Output Chapter 2 - VB 2008 by Schneider 35

Renaming the Form • Initial name is Form 1 • The Solution Explorer window

Renaming the Form • Initial name is Form 1 • The Solution Explorer window lists a file named Form 1. vb. • To rename the form, change the name of this file to new. Name. vb • new. Name should begin with prefix frm. Chapter 2 - VB 2008 by Schneider 36

Auto Hide • Hides Toolbox when not in use • Vertical push pin icon

Auto Hide • Hides Toolbox when not in use • Vertical push pin icon indicates auto hide is disabled. • Click the push pin to make it horizontal and enable auto hide. Push pin Chapter 2 - VB 2008 by Schneider 37

Positioning Controls Proximity line Chapter 2 - VB 2008 by Schneider 38

Positioning Controls Proximity line Chapter 2 - VB 2008 by Schneider 38

Aligning Controls Snap line Chapter 2 - VB 2008 by Schneider 39

Aligning Controls Snap line Chapter 2 - VB 2008 by Schneider 39

Aligning Controls Snap line Chapter 2 - VB 2008 by Schneider 40

Aligning Controls Snap line Chapter 2 - VB 2008 by Schneider 40

Tab Order Tab index The tab indices determine the order in which controls receive

Tab Order Tab index The tab indices determine the order in which controls receive the focus during tabbing. Chapter 2 - VB 2008 by Schneider 41

2. 3 Visual Basic Events • An Event Procedure Walkthrough • Properties and Event

2. 3 Visual Basic Events • An Event Procedure Walkthrough • Properties and Event Procedures of the Form • The Header of an Event Procedure Chapter 2 - VB 2008 by Schneider 42

Event • An event is an action, such as the user clicking on a

Event • An event is an action, such as the user clicking on a button • Usually, nothing happens in a Visual Basic program until the user does something and generates an event. • What happens is determined by statements. Chapter 2 - VB 2008 by Schneider 43

Sample Statements • txt. Box. Fore. Color = Color. Red • txt. Box. Visible

Sample Statements • txt. Box. Fore. Color = Color. Red • txt. Box. Visible = True • txt. Box. Text = "Hello World" General Form: control. Name. property = setting Chapter 2 - VB 2008 by Schneider 44

Sample Form txt. First txt. Second btn. Red Chapter 2 - VB 2008 by

Sample Form txt. First txt. Second btn. Red Chapter 2 - VB 2008 by Schneider 45

Focus • When you click on a text box, a cursor appears in the

Focus • When you click on a text box, a cursor appears in the text box, and you can type into the text box. • Such a text box is said to have the focus. • If you click on another text box, the first text box loses the focus and the second text box receives the focus. Chapter 2 - VB 2008 by Schneider 46

Examples of Events • btn. Show. Click • txt. Box. Text. Changed • txt.

Examples of Events • btn. Show. Click • txt. Box. Text. Changed • txt. Box. Leave General Form: control. Name. event Chapter 2 - VB 2008 by Schneider 47

The three steps in creating a Visual Basic program: 1. Create the interface; that

The three steps in creating a Visual Basic program: 1. Create the interface; that is, generate, position, and size the objects. 2. Set properties; that is, configure the appearance of the objects. 3. Write the code that executes when events occur. Chapter 2 - VB 2008 by Schneider 48

Code Editor tab Form Designer tab Method Name box Class Name box Chapter 2

Code Editor tab Form Designer tab Method Name box Class Name box Chapter 2 - VB 2008 by Schneider 49

Structure of an Event Procedure Private Sub object. Name_event(. . . ) Header Handles

Structure of an Event Procedure Private Sub object. Name_event(. . . ) Header Handles object. Name. event statements End Sub (. . . ) is filled automatically with (By. Val sender As System. Object, By. Val e As System. Event. Args) Chapter 2 - VB 2008 by Schneider 50

Create an Outline for an Event Procedure; i. e. header and End Sub •

Create an Outline for an Event Procedure; i. e. header and End Sub • Double-click on a control or • Use the Class Name and Method Name boxes. (We nearly always use the first method. ) Chapter 2 - VB 2008 by Schneider 51

Sample Form txt. First txt. Second btn. Red Double Click on txt. First Chapter

Sample Form txt. First txt. Second btn. Red Double Click on txt. First Chapter 2 - VB 2008 by Schneider 52

Code for Walkthrough Public Class frm. Demo Private Sub txt. First_Text. Changed(. . .

Code for Walkthrough Public Class frm. Demo Private Sub txt. First_Text. Changed(. . . ) Handles txt. First. Text. Changed End Sub End Class Chapter 2 - VB 2008 by Schneider 53

Code for Walkthrough Public Class frm. Demo Private Sub txt. First_Text. Changed(. . .

Code for Walkthrough Public Class frm. Demo Private Sub txt. First_Text. Changed(. . . ) Handles txt. First. Text. Changed txt. First. Fore. Color = Color. Blue End Sub End Class Chapter 2 - VB 2008 by Schneider 54

Intelli. Sense Automatically pops up to give the programmer help. txt. First. Chapter 2

Intelli. Sense Automatically pops up to give the programmer help. txt. First. Chapter 2 - VB 2008 by Schneider 55

Code Editor Click tab to return to Form Designer Chapter 2 - VB 2008

Code Editor Click tab to return to Form Designer Chapter 2 - VB 2008 by Schneider 56

Sample Form txt. First txt. Second btn. Red Double-click on btn. Red Chapter 2

Sample Form txt. First txt. Second btn. Red Double-click on btn. Red Chapter 2 - VB 2008 by Schneider 57

Code for Walkthrough Public Class frm. Demo Private Sub txt. First_Text. Changed(. . .

Code for Walkthrough Public Class frm. Demo Private Sub txt. First_Text. Changed(. . . ) Handles txt. First. Text. Changed txt. First. Fore. Color = Color. Blue End Sub Private Sub btn. Red_Click(. . . ) Handles btn. Red. Click End Sub End Class Chapter 2 - VB 2008 by Schneider 58

Code for Walkthrough Public Class frm. Demo Private Sub txt. First_Text. Changed(. . .

Code for Walkthrough Public Class frm. Demo Private Sub txt. First_Text. Changed(. . . ) Handles txt. First. Text. Changed txt. First. Fore. Color = Color. Blue End Sub Private Sub btn. Red_Click(. . . ) Handles btn. Red. Click txt. First. Fore. Color = Color. Red End Sub End Class Chapter 2 - VB 2008 by Schneider 59

Event Procedure txt. First. Leave • Select txt. First from Class Name box drop

Event Procedure txt. First. Leave • Select txt. First from Class Name box drop -down list. • Select Leave from Method Name box drop-down list. Chapter 2 - VB 2008 by Schneider 60

Code for Walkthrough Private Sub txt. First_Leave(. . . ) Handles txt. First. Leave

Code for Walkthrough Private Sub txt. First_Leave(. . . ) Handles txt. First. Leave End Sub Private Sub txt. First_Text. Changed(. . . ) Handles txt. First. Text. Changed txt. First. Fore. Color = Color. Blue End Sub Private Sub btn. Red_Click(. . . ) Handles btn. Red. Click txt. First. Fore. Color = Color. Red End Sub Chapter 2 - VB 2008 by Schneider 61

Code for Walkthrough Private Sub txt. First_Leave(. . . ) Handles txt. First. Leave

Code for Walkthrough Private Sub txt. First_Leave(. . . ) Handles txt. First. Leave txt. First. Fore. Color = Color. Black End Sub Private Sub txt. First_Text. Changed(. . . ) Handles txt. First. Text. Changed txt. First. Fore. Color = Color. Blue End Sub Private Sub btn. Red_Click(. . . ) Handles btn. Red. Click txt. First. Fore. Color = Color. Red End Sub Chapter 2 - VB 2008 by Schneider 62

Header of Event Procedure Private Sub btn. Red_Click(…) Handles btn. Red. Click Name, can

Header of Event Procedure Private Sub btn. Red_Click(…) Handles btn. Red. Click Name, can be changed. Identifies event Private Sub Button_Press(…) Handles btn. Red. Click Chapter 2 - VB 2008 by Schneider 63

Handling Multiple Events Event procedure can be invoked by two events. Private Sub Happening(.

Handling Multiple Events Event procedure can be invoked by two events. Private Sub Happening(. . . ) Handles btn. Red. Click, txt. Second. Leave txt. First. Fore. Color = Color. Red End Sub Chapter 2 - VB 2008 by Schneider 64

Altering Properties of the Form • The following won't work: frm. Demo. Text =

Altering Properties of the Form • The following won't work: frm. Demo. Text = "Demonstration" • The form is referred to by the keyword Me. Text = "Demonstration" Chapter 2 - VB 2008 by Schneider 65

Text File • Holds data to be processed by programs. • Can be created,

Text File • Holds data to be processed by programs. • Can be created, viewed, and managed by the Visual Basic IDE. • Create: Use “Add New Item” input dialog box. • View: Click on filename in Solution Explorer. • Manage: Use Solution Explorer like Windows Explorer. Chapter 2 - VB 2008 by Schneider 66

Sample Text File Mike Jones 9. 35 35 John Smith 10. 75 33 PAYROLL.

Sample Text File Mike Jones 9. 35 35 John Smith 10. 75 33 PAYROLL. TXT Chapter 2 - VB 2008 by Schneider 67

Sample Text File name hourly wage hours worked Mike Jones 9. 35 35 John

Sample Text File name hourly wage hours worked Mike Jones 9. 35 35 John Smith 10. 75 33 PAYROLL. TXT Chapter 2 - VB 2008 by Schneider 68

Our Text File Convention • PAYROLL. TXT uses one item of data per line.

Our Text File Convention • PAYROLL. TXT uses one item of data per line. That will be our convention in this book. Chapter 2 - VB 2008 by Schneider 69

Use Property Window to View all Possible Events for a Control Events button Chapter

Use Property Window to View all Possible Events for a Control Events button Chapter 2 - VB 2008 by Schneider 70

Open and Run an Existing Program • • • Click on Open Project in

Open and Run an Existing Program • • • Click on Open Project in the File menu. Navigate to the program’s folder. Click on the program’s folder. Double-click on the file with extension. sln. In the Solution Explorer double-click on the file with extension. vb. (The Form Designer will appear. ) • Press F 5 to run the program. Chapter 2 - VB 2008 by Schneider 71