Top Banner
CSC 157 (Blum) 1 Hello World
47

CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

Dec 14, 2015

Download

Documents

Phyllis Johns
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 1

Hello World

Page 2: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 2

Start/Programs/Microsoft Visual Studio .NET 2003/Microsoft Visual Studio .NET 2003

Page 3: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 3

Start Page Tabs: My Profile

Page 4: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 4

Start Page Tabs: Projects

Page 5: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 5

New Project Dialog Box

Page 6: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 6

Name the Project

Page 7: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 7

Browse for a Location

Page 8: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 8

Use Look in Drop-down box to select a location for your project

Page 9: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 9

Click on the Create New Folder button to make a folder for your project

Page 10: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 10

Enter a Name in the New Folder Dialog Box

Page 11: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 11

Click Open

Page 12: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 12

Click OK

Page 13: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 13

Designing a Form

Page 14: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 14

Place the mouse over the Toolbox icon to display the Toolbox

Page 15: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 15

Click on the tack icon to display the Toolbox continually

Page 16: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 16

Change the programming name of the form by editing the text in the (Name) textbox in

the Properties Window

Properties Window

Page 17: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 17

Right click on the Form icon in the Solution Explorer and choose Rename

Page 18: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 18

Here we are changing the name of the file that contains the code we will write. It is tradition for

it to have the same name as the Form (class).

Solution Explorer

Page 19: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 19

Right click on project icon in the Solution Explorer and choose Properties.

Page 20: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 20

Find the newly named file in the Startup object drop-down list, then click OK.

Page 21: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 21

Click on the form in the design tabpage to bring back

its Properties Window, then edit the Text property.

The form in design.

Page 22: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 22

Form

• The form is like a window.

• Think of it as a container of the other items belongs to your graphical user interface (GUI). – Technical point: we are creating a form class,

usually one must instantiate a specific object of a generic class. But if there is only one form this is done automatically for you.

Page 23: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 23

A look at what has been generated thus far in Windows Explorer

Page 24: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 24

Click on the Button icon in the toolbox

Page 25: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 25

Drag the cursor (it should appear as the button icon and cross hairs) from the upper left to the lower right of the desired position of the button

Page 26: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 26

Change the button’s (Name) property in the Properties Window

Page 27: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 27

Controls and Hungarian Notation

• The button is our first example of a control. Controls are the items placed on a form (usually visible) with which the user interacts.

• Visual Basic programming typically uses a notation scheme known as Hungarian Notation for naming controls. – The names of controls start with a prefix that describes

the type of control. – The rest of the control’s name hints at its purpose in the

program. • The first letter of the second part of the name is capitalized.

Page 28: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 28

Edit the textbox corresponding to the Text property of the button.

Page 29: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 29

Click on the Label icon in the toolbox

Page 30: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 30

Drag the cursor from the upper left to the lower right of the desired position of the label

Page 31: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 31

Change the label’s (Name) property in the Properties Window – the Hungarian prefix for label is lbl

Page 32: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 32

Click on the ellipsis button for the font dialog box

Page 33: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 33

Use the Font dialog box to change the font size and click OK

Page 34: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 34

Clear out the text property of the label

Page 35: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 35

Double click on the Message button

Page 36: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 36

This open up a FrmHello code tabpage and provides the first and last line of the btnMessage_Click method

Page 37: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 37

Event Driven Programming

• We are writing event-driven code. • An error is when something happens.

Examples include: – The user clicking a button– The program clock reaching a certain value – The system running out of memory allotted to

the program– Etc.

Page 38: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 38

Inside the button’s click event method, start entering the code that will display a message. Type the name of the label and a dot.

Page 39: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 39

Typing the dot should yield a drop-down list of label properties and methods, double click on the text property.

Page 40: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 40

Finish typing the assignment statement.

Page 41: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 41

Assignment statements

• Assignment statements direct the computer to evaluate the right-hand side and then to set the value of the property on the left-hand side to that value.

• The right-hand side of the statement in this case is a literal string – that “Hello World”

Page 42: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 42

Add comments. Comments start with an apostrophe. They do not affect the way the program executes,

but help someone to read the code.

Page 43: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 43

Click on Build/Build Solution

Page 44: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 44

Click Debug/Start

Page 45: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 45

The executing program prior to the user’s clicking the button.

Page 46: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 46

The executing program after the user’s clicking the button.

Page 47: CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.

CSC 157 (Blum) 47

Close the program by clicking the button